views:

21

answers:

1

Hello all,

When I try to send out a POST 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!

A: 

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.

vikingosegundo
Works like a charm now! Thanks a lot!
Ron