1
例如,如果字符串包含%,我遇到了NSURLRequest
问题,并执行了POST。使用POST发送数据,使用字符编码发出
在我的网站,我可以看到编码是ISO-8859-1,utf-8
为Accept-Charset
但出于某种原因,我不能得到这个职位的工作,如果它包含“%& $”等,这似乎是它不会与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];