java - iOS 中的 http 状态 400

标签 java ios response form-data

我的Web服务已经在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}")

要调用此网络服务,我的代码是这样的:

    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>

最佳答案

我假设 Web 服务是一个 java spring-mvc。 看来您没有将正确的参数传递给服务器。 如图所示here错误“客户端发送的请求在语法上不正确”的最常见问题是服务器需要您发送的参数之外的其他参数。

关于java - iOS 中的 http 状态 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18846319/

相关文章:

java - 安卓 : resuming an app after an opening notification push

ios - 如何实现 UINavigationController 用于模态呈现,而不是用于弹出窗口,具有自适应 segue

ios - 我如何从 SEL 中获取参数类型

ios - 检测 UITextField 内容变化

java一组代码不执行

c# - 从静态方法调用 Response.TransmitFile()

java - Android Multi-Touch 帮助 - 一次拖动两个对象

java - JComboBox:不可编辑但可输入

java - 使用 Java Spring 3.0 @NumberFormat 注解

c# - HttpResponse.End 与 HttpResponse.Close 与 HttpResponse.SuppressContent