Cor*_*oyd 13 iphone cocoa cocoa-touch http objective-c
我正在使用NSURLRequest发送帖子.
NSURL *url = [NSURL URLWithString:someUrlString];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [parameterString length]];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];
Run Code Online (Sandbox Code Playgroud)
在请求正文中,我正在编码以下NVP:
returnURL = http://someSite.com
帖子成功通过,但我收到了错误.该错误表示无效的网址.
所以,我把它改为:
RETURNURL = HTTP:%2F%2FsomeSite.com
有同样的错误.
我还与Todd Ditchendorf的HTTP客户端进行了双重检查,结果相同.
我知道我必须编码这个错误可以有人告诉我我做错了什么吗?
谢谢科里
**更新:感谢那些回答的人.我的NVP值中错过了&符号.当然,一旦我修好了,一切都很好.我怀疑的是,帖子正文中的网址编码是不正确的.我没有使用ASIHTTPRequest框架,但它确实帮助我解决了问题(对于我需要的东西而言是过度杀伤).**
Ale*_*lds 15
考虑使用Ben Copsey的ASIHTTPRequest框架来生成和发送同步和异步HTTTP请求(POST和GET):
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:@"http://someSite.com"] autorelease];
[request setPostValue:@"myValue1" forKey:@"myFormField1"];
[request setPostValue:@"myValue2" forKey:@"myFormField2"];
// etc.
[request start];
NSError *error = [request error];
if (!error)
NSString *response = [request responseString];
Run Code Online (Sandbox Code Playgroud)
他的框架节省了大量时间.
| 归档时间: |
|
| 查看次数: |
24937 次 |
| 最近记录: |