gpt4 book ai didi

ios - 尝试使用 NSMutableURLRequest 将非常大的 JSON 字符串上传到服务器时获取响应状态代码 : 404, header

转载 作者:行者123 更新时间:2023-11-28 19:41:50 26 4
gpt4 key购买 nike

我正在尝试使用 NSMutableURLRequest 将一个非常大的 JSON 字符串上传到服务器。如果 postData 的长度是 239741 那么它给出以下响应:

 { status code: 404, headers {
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/html";
Date = "Fri, 04 Dec 2015 09:12:30 GMT";
Server = "nginx/1.4.6 (Ubuntu)";
"Transfer-Encoding" = Identity;
} }

但是如果我尝试将 postData 长度为 206044 的 JSON 字符串发送到服务器,则数据会成功上传到服务器。

如何将不限长度的 JSON 字符串上传到服务器?

完整代码如下:

NSString *urlString = [NSString stringWithFormat:@“URL Here”];
NSData *postData = [[NSString stringWithFormat:@"data=%@",postValues] dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", (int)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setValue:[NSString stringWithFormat:@"Token %@",AuthToken] forHTTPHeaderField:@"Authorization"];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setTimeoutInterval:50];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *error1 = nil;

NSHTTPURLResponse *response=nil;
NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
NSLog(@"response is %@",response);
NSString* responseString=[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"response string is %@",responseString);
if (responseData) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error1];
return json;
}
else
NSLog(@"Error : %@",error1.description);

最佳答案

首先检查您的网络服务 URL

The 404 or Not Found error message is an HTTP standard response code indicating that the client was able to communicate with a given server, but the server could not find what was requested.

您可以使用下面列出的 Google ChromeMozila firefox 上可用的不同插件来检查您的网络服务。

  1. > POSTMAN
  2. > REST Client

希望这对您有帮助。

关于ios - 尝试使用 NSMutableURLRequest 将非常大的 JSON 字符串上传到服务器时获取响应状态代码 : 404, header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com