2010-01-26 42 views
1

例如,如果字符串包含%,我遇到了NSURLRequest問題,並執行了POST。使用POST發送數據,使用字符編碼發出

在我的網站,我可以看到編碼是ISO-8859-1,utf-8Accept-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]; 

回答

0

您可能想聽到「Content-Transfer-Encoding」。

Content-Type:text/plain;字符集= UTF-8

內容傳輸編碼:二進制

,或者如果你有問題,特別是與那些字符

內容傳輸編碼:的base64

編輯: 的「應用程序/ x-www-form-urlencoded「會使」%「符號發生。