gpt4 book ai didi

ios - 带有AFNetworking的POST,错误代码-1001

转载 作者:行者123 更新时间:2023-12-01 16:47:57 25 4
gpt4 key购买 nike

我想发布一个JSON消息以发送到服务器。我没有访问服务器本身的权限,但我知道它正在运行,并设置为在消息通过后返回成功/失败消息。服务器需要应用ID和密码才能连接

我为此使用AFNetworking。这是我正在使用的代码:

NSURL* pushServerURL = [NSURL URLWithString: @"http://myserverurl.com/"];
AFHTTPClient* networkInstance = [[AFHTTPClient alloc] initWithBaseURL: pushServerURL];

NSDictionary *parameters =[NSDictionary dictionaryWithObjectsAndKeys:
@"myappid", @"app_id", @"mypassword", @"password", nil];

NSDictionary *params =[NSDictionary dictionaryWithObjectsAndKeys:
parameters, @"user", nil];

[networkInstance postPath: @"users/login.json"
parameters: params
success:^
(AFHTTPRequestOperation *operation, id jsonResponse)
{
NSLog (@"SUCCESS");
}
failure:^
(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"FAILED");
}];

它始终失败,错误代码为-1001。

NSError在用户信息中有4个键
NSErrorFailingURLStringKey with value @"http://myserverurl.com/, 
NSErrorFailingURLKey with value <not an Objective-C object>,
NSLocalizedDescription with value "The request timed out"
NSUnderlyingError and the value has no string.

知道我做错了什么吗?

最佳答案

试试这一行代码。您可以轻松找到来自服务器的响应是什么,否则实际问题出在哪里?

[networkInstance postPath: @"users/login.json"
parameters: params
success:^(AFHTTPRequestOperation *operation, id jsonResponse) {
NSLog (@"SUCCESS");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@" Error - Statistics file upload failed: \"%@\"", [request error]);
}];

关于ios - 带有AFNetworking的POST,错误代码-1001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18484850/

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