【发布时间】:2010-01-26 20:13:40
【问题描述】:
例如,我的NSURLRequest 有问题,并且每当字符串包含 % 时都会执行 POST。
在我的网站上,我可以看到ISO-8859-1,utf-8 的编码是ISO-8859-1,utf-8,但由于某种原因,如果它包含“%&$”等,我无法让 POST 工作。似乎它不会编码它使用 UTF-8 编码。我在下面的代码中做错了吗?
NSData *postData = [credentials dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.website.com/login.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
【问题讨论】:
标签: iphone httprequest nsmutableurlrequest