2013-03-01 142 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的