我的网络服务已经在JAVA平台上准备好了。要发送请求参数,我需要使用Form-Data。我试图从我的网络服务获得响应,但我每次都只收到此错误。
-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>
答案 0 :(得分:1)
我认为Web服务是一个java spring-mvc。 您似乎没有将正确的参数传递给服务器。 如上所述here错误最常见的问题是“客户端发送的请求在语法上不正确”是服务器需要的其他参数不是您发送的参数。