2

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

知道我可能做错了什么吗?

4

1 回答 1

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]);
}];
于 2013-08-28T10:13:06.457 回答