日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用WeexSDK,网络请求信任证书的问题

發(fā)布時(shí)間:2024/1/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用WeexSDK,网络请求信任证书的问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用0.18.0版本的weexSDK,并且是手動(dòng)導(dǎo)入的SDK。

在項(xiàng)目中創(chuàng)建一個(gè)SDResourceRequest(名字隨意)類繼承WXResourceRequestHandlerDefaultImpl,遵循

WXResourceRequestHandler,NSURLSessionDelegate協(xié)議,如下圖:

在SDResourceRequest.m中實(shí)現(xiàn)- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler方法,代碼如下:

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler {//AFNetworking中的處理方式NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;__block NSURLCredential *credential = nil;//判斷服務(wù)器返回的證書是否是服務(wù)器信任的if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];/*disposition:如何處理證書NSURLSessionAuthChallengePerformDefaultHandling:默認(rèn)方式處理NSURLSessionAuthChallengeUseCredential:使用指定的證書
      NSURLSessionAuthChallengeCancelAuthenticationChallenge:取消請(qǐng)求*/if (credential) {disposition = NSURLSessionAuthChallengeUseCredential;} else {disposition = NSURLSessionAuthChallengePerformDefaultHandling;}} else {disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;}//安裝證書if (completionHandler) {completionHandler(disposition, credential);}}

?

使用下面的方法無效,不知道為什么

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{/*方法一 信任所有證書*/if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];if(completionHandler)completionHandler(NSURLSessionAuthChallengeUseCredential,credential);} }

?

使用cocoaPods導(dǎo)入WeexSDK應(yīng)該沒有問題,但是手動(dòng)導(dǎo)入的WeexSDK可能沒有WXResourceRequestHandlerDefaultImpl.h,可以在git上下載weexSDK源碼把WXResourceRequestHandlerDefaultImpl.h放在外面,重新打包后在導(dǎo)入項(xiàng)目,如圖:

?

?

參考:

AFNetworking中的處理方式的參考鏈接找不到了

https://www.jianshu.com/p/bcb19fe43909

https://www.jianshu.com/p/3cc2ec005761

?

轉(zhuǎn)載于:https://www.cnblogs.com/lulushen/p/9640150.html

總結(jié)

以上是生活随笔為你收集整理的使用WeexSDK,网络请求信任证书的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。