ASIHTTPRequest使用心得

1、 [NSURL URLWithString:urlString],urlString的类型必须正确,必须以http或者https开头,在一次项目中因为在http前面多了个空格,导致字符串转化为NSURL类型时为空。

2、在使用ASI发送请求时,相同信息可以放在http头部统一处理,这样就可以在每次请求中加入相同的参数

3、使用 [NSURL URLWithString:urlString]导致返回的url为nil,因为

Return Value
An NSURL object initialized with URLString. If the string was malformed, returns nil.

Discussion
This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
所以使用
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//通过utf-8编码,来规避一些特殊字符
url = [NSURL URLWithString:urlStr];

4、使request在后台持续运行,直到回调完成

ASIHTTPRequest supports running requests in the background:

[request setShouldContinueWhenAppEntersBackground:YES];
5、禁用安全证书校验

在用https连接时可能会使用到 ,如果你有一个自签名的证书,你可能想禁用证书校验来做测试。这里我建议你从一个可信的CA购买证书,并为生产(production)期的app启用证书校验。

[request setValidatesSecureCertificate:NO];
(转自: http://blog.csdn.net/yhawaii/article/details/7910483)

 

你可能感兴趣的:(ASIHTTPRequest使用心得)