我有一个疯狂的问题。我有一个 IIS7,我需要通过 POST 发布公式,还需要通过 NTLM 进行身份验证,所有这些东西都需要通过 SSL 连接。到目前为止,我设法将它连接到服务器并发布我的数据。
在 POST 之后,我将获得成功的 302 响应,它将我重定向到第二页。DefaultHttpClient 连接到网络服务器进行身份验证并发布数据。到目前为止一切正常。但是现在客户端关闭了连接并打开了第二个连接(这种行为对我来说很重要)但这不是我的问题。在第二个连接上,客户端忘记了如何在 IIS 上进行身份验证,并因 401 身份验证错误而中断。
到目前为止,我可以看到这是DefaultHttpClient 源中的一个固定错误,但 Android 似乎使用了这个库的旧版本。如何修复似乎存在于世界上每台安卓设备上的错误?
以下是我通讯的相关部分:
POST /login/ HTTP/1.1
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
Host: example.com
Connection: Keep-Alive
Cookie: ASPSESSION...
[the post data]
HTTP/1.1 401 Unauthorized
Content-Type: text/html
Server: Microsoft-IIS/7.5
WWW-Authenticate: NTLM
Content-Length: 1344
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
...
</html>
POST /login/ HTTP/1.1
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
Host: example.com
Connection: Keep-Alive
Cookie: ASPSESSION...
Authorization: NTLM ABC...==
[the post data]
HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
WWW-Authenticate: NTLM ABC...DEF
Content-Length: 341
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Authorized</TITLE>...</HTML>
POST /login/ HTTP/1.1
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
Host: example.com
Connection: Keep-Alive
Cookie: ASPSESSION...
Authorization: NTLM ABC...DEF
[the post data]
HTTP/1.1 302 Moved Temporary
Cache-Control: private,no-cache
Pragma: no-cache
Content-Length: 31
Content-Type: application/json; Charset=UTF-8
Expires: Fri, 07 Dec 2012 07:01:00 GMT
Location: /login/step2.asp
Server: Microsoft-IIS/7.5
Set-Cookie: [...] path=/login/; HttpOnly;
Persistent-Auth: true
[some response]
--- 现在连接是否关闭并打开第二个 https 连接 ---
GET /login/step2.asp HTTP/1.1
Host: example.com
Connection: Keep-Alive
Cookie: ASPSESSION...
HTTP/1.1 401 Unauthorized
Content-Type: text/html
Server: Microsoft-IIS/7.5
WWW-Authenticate: NTLM
Content-Length: 1344
---然后连接再次关闭---
你知道解决这个问题的方法吗?