开发者

iPhone POST request truncates string

When I try to send out a PO开发者_运维问答ST request to a specific site the string I try to send gets cut off. When I check the length of the string in Xcode it is about 55000 characters long. The amount of characters received on the site is about 4500. This is my code:

-(IBAction)convert {

NSString *rosterText = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"];

NSString *params = [[NSString alloc] initWithFormat:@"roster=%@", rosterText];

NSString *paramsLength = [NSString stringWithFormat:@"%d", [params length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.thesite/index.php"]];

[request setHTTPMethod:@"POST"];

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];

[request setValue:paramsLength forHTTPHeaderField:@"Content-Length"];

[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"length = %@",paramsLength);

[webView loadRequest:request]; 

[params release];

[request release];

}

I have a form on the site where you can manually insert the string and that all works fine, so seems to me something is going wrong within the encoding of the POST data.

Anybody know whats going wrong here? Just can't seem to figure it out!

Thanks a lot!


I am not sure, what is going wrong, but I'd suggest you to use ASIHTTPRequest.

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier. It is written in Objective-C and works in both Mac OS X and iPhone applications.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜