Android中的NTLM代理身份验证

时间:2013-06-17 13:53:15

标签: android proxy httpclient ntlm apache-httpclient-4.x

我试图通过使用NTLM代理身份验证来使用Httppost操作。我用过JCIFSEngine。但我仍然得到一个错误。

这是我的代码:

BasicHttpParams params = new BasicHttpParams();
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
HttpConnectionParams.setSoTimeout(params, connectionTimeout);
httpclient = new DefaultHttpClient(cm, params);

httpclient.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory());
    httpclient.getCredentialsProvider().setCredentials(new AuthScope("proxyServerIP", 80, "http", "DOMAIN"),new NTCredentials("userNAme", "pass", null, "DOMAIN")); 

我收到此错误:

<HEAD><TITLE>Proxy Authorization Required</TITLE></HEAD>
<BODY BGCOLOR="white" FGCOLOR="black"><H1>Proxy Authorization Required</H1><HR>
<FONT FACE="Helvetica,Arial"><B>
Description: Authorization is required for access to this proxy<BR><BR>
</B>Error Code: <BR>(NTLM) NA c<BR><BR>
User Agent: <BR><BR><BR>
Error Detail: <BR><PRE>[2013/06/14 17:30:44.539735,  1] libsmb/ntlmssp.c:342(ntlmssp_update)
  got NTLMSSP command 3, expected 1
</PRE><BR><BR></B></FONT>
<HR>
<!-- default "Proxy Authorization Required" response (407) -->
</BODY>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

如果您想尝试Apache Software Foundation解决问题的方法:

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#ntlm

4.9。 NTLM身份验证

从版本4.1开始,HttpClient提供对NTLMv1,NTLMv2和NTLM2会话身份验证的完全支持。人们仍然可以继续使用外部NTLM引擎,例如Samba项目开发的JCIFS库,作为其Windows互操作性程序套件的一部分。