2013-02-28 69 views
1

現在,我打算髮送一個NSURLRequest到服務器的本地證書供服務器驗證。但我檢查NSURLRequest中的函數,我找不到包含證書的方法。有誰知道如何在NSUrlRequest中包含證書?或者我必須使用開源功能,如ASIHttpRequestiPhone - 在請求中發送證書

回答

0

嘗試給看看這個挺好的教程

Authenticating an HTTP Request with Client Certificates in iOS

它說明了如何使用NSURLConnectionDelegate方法

- (void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 

爲了提供證書。 讓我知道這是否有幫助。

UPDATE 如果只支持適用於iOS> = 5.0提供,最好是採用新的非過時方法

connection:willSendRequestForAuthenticationChallenge

+0

我可以說[challenge.sender useCredential:憑據forAuthenticationChallenge:挑戰] *將證書發送回服務器 – 2013-02-28 10:59:08

+0

是的,鑑於*憑證*實際上包含所有證書數據: NSURLCredential *憑證= [NSURLCredential憑證憑證:身份憑證:(NSArray *)certArray持久性:NSURLCredentialPersi stencePermanent]; – 2013-02-28 11:07:01

+0

好的,明白了,謝謝。 – 2013-03-01 01:42:46