欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS9蘋(píng)果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法

 更新時(shí)間:2016年01月08日 13:33:43   投稿:mrr  
這篇文章主要介紹了iOS9蘋(píng)果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法的相關(guān)資料,需要的朋友可以參考下

解決方法:

在info.plist 加入key

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

下面給大家介紹ios中http 和https 協(xié)議的訪問(wèn)

最近做個(gè)項(xiàng)目,開(kāi)始采用的是HTTP協(xié)議實(shí)現(xiàn)客戶(hù)端和服務(wù)器端的交互,后來(lái)需要改成HTTPS協(xié)議。在修改的過(guò)程中發(fā)現(xiàn)了一些問(wèn)題,解決方案如下:

HTTP:

NSString *urlString =[NSString stringWithFormat:@"https://127.0.0.1/default.aspx?USER=%@",@"111"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"GET"];
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSMutableString *result = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"The result string is :%@",result); 

HTTPS

事件觸發(fā)

{ 
NSString *urlString =[NSString stringWithFormat:@"https://127.0.0.1/default.aspx?USER=%@",@"111"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5];
//設(shè)置請(qǐng)求方式為get
[request setHTTPMethod:@"GET"];
//添加用戶(hù)會(huì)話(huà)id
[request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
//連接發(fā)送請(qǐng)求
finished = false;
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//堵塞線程,等待結(jié)束
while(!finished) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
} 
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response 
{}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
//[_waitingDialog dismissWithClickedButtonIndex:0 animated:NO];
[connection release];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{ 
}
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection{
return NO;
}
//下面兩段是重點(diǎn),要服務(wù)器端單項(xiàng)HTTPS 驗(yàn)證,iOS 客戶(hù)端忽略證書(shū)驗(yàn)證。
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
} 
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
NSLog(@"didReceiveAuthenticationChallenge %@ %zd", [[challenge protectionSpace] authenticationMethod], (ssize_t) [challenge previousFailureCount]);
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
[[challenge sender] useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[[challenge sender] continueWithoutCredentialForAuthenticationChallenge: challenge];
}
} 
NSLog(@"get the whole response");
//[receivedData setLength:0];
}
//處理數(shù)據(jù) 
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{ 
} 

相關(guān)文章

  • IOS如何在Host App 與 App Extension 之間發(fā)送通知

    IOS如何在Host App 與 App Extension 之間發(fā)送通知

    這篇文章主要介紹了IOS如何在Host App 與 App Extension 之間發(fā)送通知 的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • iOS runtime forwardInvocation詳解及整理

    iOS runtime forwardInvocation詳解及整理

    這篇文章主要介紹了 iOS runtime forwardInvocation詳解及整理的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • ios實(shí)現(xiàn)自動(dòng)獲取label高度、寬度及最后一個(gè)位置詳解

    ios實(shí)現(xiàn)自動(dòng)獲取label高度、寬度及最后一個(gè)位置詳解

    這篇文章主要給大家介紹了關(guān)于ios如何實(shí)現(xiàn)自動(dòng)獲取label高度、寬度及最后一個(gè)位置的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • IOS 中NSTimer定時(shí)器的使用

    IOS 中NSTimer定時(shí)器的使用

    這篇文章主要介紹了IOS 中NSTimer定時(shí)器的使用的相關(guān)資料,希望通過(guò)本文能幫助到大家,能讓大家徹底理解使用該方法,需要的朋友可以參考下
    2017-10-10
  • iOS 導(dǎo)航欄自帶頁(yè)面右滑pop使用示例

    iOS 導(dǎo)航欄自帶頁(yè)面右滑pop使用示例

    本篇文章主要介紹了iOS 導(dǎo)航欄自帶頁(yè)面右滑pop使用示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • iOS開(kāi)發(fā)刪除storyboard步驟詳解

    iOS開(kāi)發(fā)刪除storyboard步驟詳解

    這篇文章主要為大家介紹了iOS系列學(xué)習(xí)之刪除storyboard步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • iOS開(kāi)發(fā)傻瓜式微信支付的方法教程

    iOS開(kāi)發(fā)傻瓜式微信支付的方法教程

    最近因?yàn)楣ぷ鞯男枰?,要開(kāi)發(fā)微信支付,發(fā)現(xiàn)網(wǎng)上的很多教程過(guò)于復(fù)雜,索性自己寫(xiě)一篇,所以下面這篇文章主要跟大家分享了關(guān)于iOS開(kāi)發(fā)傻瓜式微信支付的方法教程,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友們下面來(lái)一起看看吧。
    2017-07-07
  • ios利用RunLoop原理實(shí)現(xiàn)去監(jiān)控卡頓實(shí)例詳解

    ios利用RunLoop原理實(shí)現(xiàn)去監(jiān)控卡頓實(shí)例詳解

    這篇文章主要為大家介紹了ios利用RunLoop原理實(shí)現(xiàn)去監(jiān)控卡頓實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • iOS 檢測(cè)網(wǎng)絡(luò)狀態(tài)的兩種方法

    iOS 檢測(cè)網(wǎng)絡(luò)狀態(tài)的兩種方法

    一般有Reachability和AFNetworking監(jiān)測(cè)兩種方式,都是第三方的框架,下文逐一詳細(xì)給大家講解,感興趣的朋友一起看看吧
    2016-10-10
  • 快速解決ios微信下audio無(wú)法自動(dòng)播放的問(wèn)題

    快速解決ios微信下audio無(wú)法自動(dòng)播放的問(wèn)題

    下面小編就為大家分享一篇快速解決ios微信下audio無(wú)法自動(dòng)播放的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03

最新評(píng)論