集成阿里 httpdns post請求的問題

前些天集成了阿里的httpdns服務(wù),

sdk集成完成了,但是在請求的的時候,出現(xiàn)-1002,-999,502等錯誤,我用的網(wǎng)絡(luò)庫是afn;

問了阿里的技術(shù)支持,給了幾個鏈接,然并卵…………此處一萬只曹尼瑪飄過。



為什么需要httpdns呢,防止DNS劫持。DNS劫持請自行百度。

其實這里的基本邏輯并不復(fù)雜,就是通過域名獲取ip,真正發(fā)起請求的時候把之前使用域名的地方替換為ip。在請求頭里面添加host字段就可以了。

坑一:替換以后無法通過https證書驗證

解決辦法:?跳過證書校驗過程 創(chuàng)建AFHTTPSessionManager對象時候 設(shè)置一下2個block

[manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession* _Nonnull session,NSURLAuthenticationChallenge* _Nonnull challenge,NSURLCredential*__autoreleasing _Nullable * _Nullable credential) {

NSURLSessionAuthChallengeDisposition disposition =NSURLSessionAuthChallengePerformDefaultHandling;

if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

*credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];

disposition =NSURLSessionAuthChallengeUseCredential;

}else{

disposition =NSURLSessionAuthChallengePerformDefaultHandling;

? ? ? ? }

returndisposition;

? ? }];

[manager setTaskDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession* _Nonnull session,NSURLSessionTask* _Nonnull task,NSURLAuthenticationChallenge* _Nonnull challenge,NSURLCredential*__autoreleasing? _Nullable * _Nullable credential) {

NSURLSessionAuthChallengeDisposition disposition =NSURLSessionAuthChallengePerformDefaultHandling;

if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

*credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];

disposition =NSURLSessionAuthChallengeUseCredential;

}else{

disposition =NSURLSessionAuthChallengePerformDefaultHandling;

? ? ? ? }

returndisposition;

? ? }];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. 將后臺給的.cer證書直接拖進工程, 別忘記勾選taget 2. .h // 導(dǎo)入MBProgress和AF...
    skma閱讀 634評論 0 1
  • 第一篇第二篇大概是把下載圖片緩存圖片的這個邏輯走完了,里面涉及好多類。 羅列一下 UIView+WebCache ...
    充滿活力的早晨閱讀 841評論 0 1
  • 建議去看原文 AFURLSessionManager _AFURLSessionTaskSwizzling 當時看...
    泥孩兒0107閱讀 648評論 0 0
  • 首先需要設(shè)置WKNavigationDelegate代理實現(xiàn)方法: - (void)webView:(WKWebV...
    vicool閱讀 7,036評論 0 4
  • 昨天周日爸爸本來是去哥哥那給侄子做飯去了,但出去辦完事回來卻發(fā)現(xiàn)爸爸怎么回來了,一問,才知道在那邊炒菜炒的多了...
    雪兒在成長閱讀 291評論 0 1

友情鏈接更多精彩內(nèi)容