我想使用 ASIHttpRequest实现如下的功能
POST HTTP/1.1 http://www.163.com
HOST:www.163.com
ContentLenght: 10
aaaaaaaaaa
假设是以上这样的,那请问我用ASIHttpRequest如何来组织上面的数据呢?
第一次使用 ASIHttpRequest 了解的不多,先谢谢了!
------最佳解决方案--------------------
大概写下
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:@“htttp://”
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue: @"http://tempuri.org/GetSmsVerifyCodeInfo" forHTTPHeaderField:@"SOAPAction"];
//设置Content-length
[request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
//设置请求类型 POST或GET
[request setHTTPMethod:@"POST"];
NSString *soapMessage=@"a=1&b=2&c=3";
//设置请求Body(只有post方式有)
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
//然后NSURLConnection
------其他解决方案--------------------
POST 应该使用 ASIFormDataRequest 组织数据
------其他解决方案--------------------
使用方法:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];
------其他解决方案--------------------
我现在将代码实现如下:
NSString *myRequestString = @"[2012112618351111,T21,2,18@111111111111111111@222222222222222222@333333333333333333]";
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSURL * url = [NSURL URLWithString:@"http://211.140.2.123:8080/terminal/gprs"];
ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request setHTTPBody:myRequestData];