最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2016年01月08日 13:33:43   投稿:mrr  
這篇文章主要介紹了iOS9蘋果將原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é)議的訪問

最近做個(gè)項(xiàng)目,開始采用的是HTTP協(xié)議實(shí)現(xiàn)客戶端和服務(wù)器端的交互,后來需要改成HTTPS協(xié)議。在修改的過程中發(fā)現(xià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è)置請求方式為get
[request setHTTPMethod:@"GET"];
//添加用戶會話id
[request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
//連接發(fā)送請求
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 客戶端忽略證書驗(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)文章

最新評論

清涧县| 巴楚县| 景德镇市| 滁州市| 田林县| 淮滨县| 涞源县| 怀远县| 垦利县| 简阳市| 城步| 怀柔区| 宜兰县| 丹东市| 石台县| 三门县| 西乌珠穆沁旗| 万盛区| 大渡口区| 罗定市| 清水县| 越西县| 卫辉市| 昭通市| 平阴县| 麻栗坡县| 南平市| 环江| 水城县| 永新县| 双流县| 阿坝县| 贡山| 钟祥市| 斗六市| 象山县| 贡嘎县| 五家渠市| 宜黄县| 湘潭市| 蒙城县|