2013-03-01 101 views
0

我正在使用AFNetworking和iPad应用程序通过使用https与自签名证书连接到服务器。AFNetworking自签名证书iOS 5.1和6.1

在运行iOS 6.1这一切工作正常我的设备,但是当我们测试在iOS 5.1模拟器和5.1设备,我得到一个403响应。

我们试过:

#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ 

和:

[operation setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) { 
    return YES; 
}]; 

如在别处建议,但这些还是给了同样的错误。这被发送到AFHTTPRequestOperation的不良区的误差的NSLog:

Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 403" UserInfo=0x10337330 {NSLocalizedRecoverySuggestion=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<HTML><HEAD><TITLE>The page cannot be displayed</TITLE> 
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252"> 
<STYLE type="text/css"> 
    BODY { font: 8pt/12pt verdana } 
    H1 { font: 13pt/15pt verdana } 
    H2 { font: 8pt/12pt verdana } 
    A:link { color: red } 
    A:visited { color: maroon } 
</STYLE> 
</HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD> 

<h1>The page cannot be displayed</h1> 
You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed. 
<hr> 
<p>Please try the following:</p> 
<ul> 
<li>Contact the Web site administrator if you believe this directory should allow execute access.</li> 
</ul> 
<h2>HTTP Error 403.1 - Forbidden: Execute access is denied.<br>Internet Information Services (IIS)</h2> 
<hr> 
<p>Technical Information (for support personnel)</p> 
<ul> 
<li>Go to <a href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft Product Support Services</a> and perform a title search for the words <b>HTTP</b> and <b>403</b>.</li> 
<li>Open <b>IIS Help</b>, which is accessible in IIS Manager (inetmgr), 
and search for topics titled <b>Configuring ISAPI Extensions</b>, <b>Configuring CGI Applications</b>, <b>Securing Your Site with Web Site Permissions</b>, and <b>About Custom Error Messages</b>.</li> 
<li>In the IIS Software Development Kit (SDK) or at the <a href="http://go.microsoft.com/fwlink/?LinkId=8181">MSDN Online Library</a>, search for topics titled <b>Developing ISAPI Extensions</b>, <b>ISAPI and CGI</b>, and <b>Debugging ISAPI Extensions and Filters</b>.</li> 
</ul> 

</TD></TR></TABLE></BODY></HTML> 
, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x875be10>, NSErrorFailingURLKey=..., NSLocalizedDescription=Expected status code in (200-299), got 403, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest ...>} 

我已经改为“...”

任何建议的网址是什么?

+1

结果似乎没有任何连接到自签名证书或类似。您是否确定您在所有测试平台上都使用完全相同的版本?否则,为什么不使用Charles Proxy来检查测试设备的服务器访问之间的确切区别。 – Till 2013-03-01 00:57:59

+0

是的,我认为你是对的。我绝对使用完全相同的版本。如果我在5.1模拟器中运行应用程序,那么我得到那个错误,然后我切换到6.1模拟器,它工作正常,没有错误。与从Xcode项目运行到5.1设备和6.1设备一样......真的很奇怪。 – Dos43 2013-03-01 01:06:52

+0

也许服务器端(脚本)检查UserAgent并且只允许iOS6设备?再一次,试用Charles Proxy。通过使用Charles的重写规则,您可以轻松伪造旧设备的用户代理。 – Till 2013-03-01 01:16:14

回答

0

解决了这一问题,设定的我的NSMutableURLRequest

[request setHTTPMethod:@"POST"]; 

我没有资本“POST” ......显然HTTP方法时对5.x的一个问题,但不是6.x的