0

私の Web サービスは、JAVA プラットフォームで準備されています。リクエスト パラメータを送信するには、Form-Data を使用する必要があります。Web サービスからの応答を取得しようとしていますが、毎回このエラーしか表示されません。

    -JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x71a7010 {NSLocalizedDescription=Unrecognised leading character}")

この Web サービスを呼び出すには、私のコードは次のとおりです。

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:webserviceURL]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application" forHTTPHeaderField:@"content-type"];
//this is hard coded based on your suggested values, obviously you'd probably need to make this more dynamic based on your application's specific data to send
NSString *postString = @"username=test123&password=rgs&gsf&emailid=rhiuhh@fgfggr.com";
NSData *data = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
[request setValue:[NSString stringWithFormat:@"%u", [data length]] forHTTPHeaderField:@"Content-Length"];
[NSURLConnection connectionWithRequest:request delegate:self];


NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ]; // send data to the web service
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
NSString *trimmedString = [returnString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSString *trimmedString1 = [trimmedString stringByReplacingOccurrencesOfString:@"\t" withString:@""];
trimmedString1 = [trimmedString1 stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSLog(@"json string %@",trimmedString);
NSMutableArray *dic = [trimmedString1 JSONValue];
NSMutableDictionary *dic1 = [dic objectAtIndex:0];
return dic1;

これから抜け出すのを手伝ってください。

ここで JSON 文字列を検索します。

    json string <html><head><title>Apache Tomcat/6.0.35 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.35</h3></body></html>
4

1 に答える 1

1

Web サービスは Java spring-mvc だと思います。サーバーに正しいパラメーターを渡していないようです。ここで示されているように、「クライアントから送信された要求は構文的に正しくありません」というエラーの最も一般的な問題は、サーバーが送信したパラメーター以外のパラメーターを予期していることです。

于 2013-09-17T13:52:45.653 に答える