使用AFNetworking进行POST,错误代码为-1001

时间:2013-08-28 10:02:30

标签: ios afnetworking

我想POST一条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.

知道我可能做错了吗?

1 个答案:

答案 0 :(得分:0)

试试这行代码。您可以轻松找到来自服务器的响应,或者实际问题在哪里?

[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]);
}];