2011-04-10 5 views
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> 

모든 도움을 주시면 감사하겠습니다.

+0

. 이 오류는 서버 프로그램에서 예외가 발생하여 발생할 수 있습니다. 서버에서 디버그 모드를 활성화하여 응답에서 전체 예외를 보거나 로그를보고 오류가 무엇인지 확인하십시오. –

+0

원시 요청과 응답을 게시했습니다. 우리가 얻을 수있는 최선의 디버깅이 아닌가? – ofirbt

답변

0

게시 된 코드에 오류가 있습니다.

NSData* requestData = [NSData dataWithBytes:[reqString UTF8String] length:[reqString length]]; 

이 행 (질문의 코드에서 원래이었다) 오류를 생성 - 대신 배열에서 반환 된 바이트의 길이를 복용 : "[reqString UTF8String에가]"잘못된 길이가 주어되었다 - 길이 있는 NSString ...

고정 코드 :

이 나에게 서버 측의 문제처럼 보인다
const char *utf8String = [reqString UTF8String]; // no need to free me - autoreleased object returned. 
NSInteger l = strlen(utf8String); 
NSData *requestData = [NSData dataWithBytes:utf8String length:l]; 
관련 문제