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];