![](/img/trans.png)
[英]How can I fix this unusual bug that is causing my android app to crash on certain phones?
[英]How to fix a bug in the android source for my app?
我有一个疯狂的问题。 我有一个IIS7,我需要通过POST发布公式,也需要通过NTLM进行身份验证,所有这些都通过SSL连接进行。 到目前为止,我已经成功地将其连接到服务器并发布了数据。
开机自检后,我将获得成功的302响应,该响应将我重定向到第二页。 DefaultHttpClient连接到Web服务器进行身份验证并发布数据。 到目前为止,一切正常。 但是现在客户端关闭了连接并打开了第二个连接(这个行为对我有好处),但这不是我的问题。 在第二个连接上,客户端忘记了如何在IIS上进行身份验证,并因401身份验证错误而中断。
到目前为止,我可以看到这是DefaultHttpClient源代码中的固定错误,但是Android似乎使用了该库的旧版本。 如何解决世界上每一个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
---并且连接再次关闭---
您知道一种解决方法吗?
您为什么不只获取DefaultHttpClient
新版本的库并将其包含在您的项目中?
好吧,这不是解决方案,只是解决我的问题的方法,但这可能会有帮助。 我在DefaultHttpClient
中覆盖了我自己处理重定向的createClientRequestDirector
函数。
连接关闭的原因是我使用主机名,所以我连接到IP而不是主机名。 结果是,如果可以通过比较源URL和目标URL来重用连接,则客户端在重定向时会看上去。 因此,它将与https://www.example.com/
一起使用https://127.0.0.1/
进行配对,这将失败,并且连接将被关闭。
我的解决方案是我自己检查这一部分。 如果主机名和IP匹配,我将返回上一次使用的IP。 结果是该连接可以重用,并且我没有在上面链接的错误中运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.