0
我有一個iPhone模擬器應用程序作爲客戶端和WCF-REST,json編碼服務在IIS 7.0服務器上運行。 我試圖發送一些希伯來字符作爲參數的服務和服務器返回錯誤代碼400 - 錯誤的請求。 當我發送一個英文字符串時,服務器按照它應該處理的字符串。希伯來語作爲服務器端的垃圾信息
該代碼用於字符串編碼看起來像這樣:
注意,「參數」是將要被髮送到服務器,排序爲PARAMETER_NAME => PARAMETER_VALUE的參數。
//RPC JSON
NSString* reqString = [parameters JSONRepresentation];
//Request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSData* requestData = [NSData dataWithBytes:[reqString UTF8String] length:[reqString length]];
//prepare http body
[request setHTTPMethod: @"POST"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
請求和響應我(用空靈得到這個)獲得在服務器端:
請求:
POST /SmsliMobileService.svc/SetContactGroups HTTP/1.1
Host: 192.168.10.22:8081
User-Agent: Beeper_3/1.0 CFNetwork/485.12.7 Darwin/10.7.0
Content-Length: 89
Accept: application/json
Content-Type: application/json; charset=UTF-8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive
響應:
{"ApplicationID":"98534bb6-82ef-4937-83e7-10f65780bf36","contact_id":43,"groups":"עבו×HTTP/1.1 400 Bad Request
Content-Length: 1647
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sun, 10 Apr 2011 07:46:09 GMT
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Request Error</title>
<style>BODY { color: #000000; background-color: white; font-family: Verdana; margin- left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding- bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background- color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font- size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding- left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre- wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;} </style>
</head>
<body>
<div id="content">
<p class="heading1">Request Error</p>
<p>The server encountered an error processing the request. See server logs for more details.</p>
</div>
</body>
</html>
任何幫助將不勝感激。
這看起來像一個服務器端的問題給我。該錯誤可能是由服務器程序中的任何異常引發的。在服務器上啓用調試模式,以便您可以在響應中看到完整的異常,或者查看日誌,以查看錯誤是什麼。 – 2011-04-10 09:00:23
我已經發布了原始請求和響應。這不是我們能得到的最好的調試嗎? – ofirbt 2011-04-10 09:27:59