ASIHttpRequest常用方法

jopen 11年前發布 | 40K 次閱讀 iOS開發 移動開發 ASIHTTPRequest

第一、根據url創建請求    

ASIHTTPRequest *httpRequest = [ASIHTTPRequest requestWithURL:url];  

第二、設置請求的方法

   [httpRequest setRequestMethod:@"GET"];
第三、設置最大連接超時時間 

  [httpRequest setTimeOutSeconds:60];

第四、代理方法表示請求成功

- (void)requestFinished:(ASIHTTPRequest *)request
{
    UIImage *image=[UIImage imageWithData:request.responseData];
    self.image=image;
}

第五、代理方法表示請求失敗

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error=request.error;
    NSLog(@"請求出錯:%@",error);
}

第六、通過block設置請求失敗

    [httpRequest setFailedBlock:^{
        NSError *error=httpRequest.error;
        NSLog(@"請求出 錯:%@",error);
        
    }];

第七、通過一個block來實現完成功能回調
        [httpRequest setCompletionBlock:^{
            [loadingView hide:YES];

第八、ios 4以上,是否開啟后臺執行

    [httpRequest setShouldContinueWhenAppEntersBackground:YES];
 第九 設置超時自動重傳
    [httpRequest setNumberOfTimesToRetryOnTimeout:2];
 第十、獲取cookies
    NSMutableArray *cookie=[httpRequest requestCookies];
 第十一、清除cookies
    [ASIHTTPRequest clearSession];
 第十二、設置cookie
    [ASIHTTPRequest setSessionCookies:cookie];
 第十三、當前網絡是否可用
    [ASIHTTPRequest isNetworkInUse];
 第十四、判斷是否為2G/3G
    [ASIHTTPRequest isNetworkReachableViaWWAN];
  第十五、網絡請求時,關閉狀態顯示欄的loading
    [ASIHTTPRequest setShouldUpdateNetworkActivityIndicator:NO];

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!