Saturday, September 28, 2013

ASIHttpRequest POST data queries

I want to use to achieve the following functions
ASIHttpRequest
POST HTTP/1.1 http://www.163.com
HOST: www.163.com
ContentLenght: 10

aaaaaaaaaa


Assumption is more like this, then I ask how I used ASIHttpRequest to organize the data above it?

First use ASIHttpRequest know much, thank!
Reply:
POST organizational data should be used ASIFormDataRequest
Reply:
 
Probably wrote
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"];

/ / Set the Content-length
[Request addValue: msgLength forHTTPHeaderField: @ "Content-Length"];
/ / Set the request type POST or GET
[Request setHTTPMethod: @ "POST"];
NSString * soapMessage = @ "a = 1 & b = 2 & c = 3";
/ / Set the request Body (only post way there)
[Request setHTTPBody: [soapMessage dataUsingEncoding: NSUTF8StringEncoding]];

/ / Then NSURLConnection


Reply:
quote 1 floor darkdong reply:
POST should use ASIFormDataRequest organize data



I now realize the code is as follows:
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];

[Request addRequestHeader: @ "User Agent" value: @ "13800138000"];
[Request addRequestHeader: @ "Host" value: @ "http://211.140.2.123:8080/terminal/gprs"];

[Request setDelegate: self];
[Request startAsynchronous];

1 The compiler does not respond
warned setHTTPBody(2) After running emerge [ASIFormDataRequest setHTTPBody:]: unrecognized selector sent to instance error
May I ask how to solve this big cow?

Reply:
Usage:
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"];
Reply:
4th Floor darkdong reply quote:
Usage:
ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL: url];
[Request setPostValue: @ "Ben" forKey: @ "first_name"];
[Request setPostValue: @ "Copsey" forKey: @ "last_name"];
......


Use this method you have achieved thanks!


But I still want to know when I am using ASIFormDataRequest where the problem lies! !
Reply:
Well above just quoted the wrong floor, I use two methods NSMutableURLRequest

No comments:

Post a Comment