我试图通过标准方式向NTLM身份验证发送请求到网络服务:
- (void)connection:(NSURLConnection *)connection
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] > 0) {
[[challenge sender] cancelAuthenticationChallenge:challenge];
} else {
NSURLCredential *cred = [NSURLCredential
credentialWithUser:username
password:password
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
}
}
GET请求正常,但POST请求有问题。 NTLM握手过程丢失POST数据。它看起来像这样:
1: iOS --> Web POST {body JSON}
2: iOS <-- Web 401 Unauthorized
WWW-Authenticate: NTLM
3: iOS --> Web POST (empty POST request, no body data!)
Authorization: NTLM <base64-encoded type-1-message>
4: iOS <-- Web 401 Unauthorized
WWW-Authenticate: NTLM <base64-encoded type-2-message>
5: iOS --> Web POST (empty POST request, no body data!)
Authorization: NTLM <base64-encoded type-3-message>
6: iOS <-- Web 500 Internal Error (it's normal, because body is empty)
Android应用没有问题,它按预期工作。有什么想法吗?