我想POST一個json消息發送到服務器。我沒有訪問服務器本身,但我知道它正在工作並設置爲在消息通過時返回成功/失敗消息。服務器需要應用程序ID和密碼才能連接帶AFNetworking的POST,錯誤代碼-1001
我正在使用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在用戶信息
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個按鍵?
-1001通常意味着請求超時。你的網絡工作正常嗎? – tilo
我們可以得到錯誤代碼的錯誤描述嗎?那麼嘗試與本地的'NSURLConnection'相同呢? –
網絡應該正常工作。其他幾個應用程序正在使用它,並正常工作。我不知道如何使用NSURLConnection,我堅信在這個網絡編程的東西我的舒適區。錯誤返回了4個鍵,其中值爲myurl的NSErrorFailingURLStringKey,值爲<不是Objective-C對象的NSErrorFailingURLKey>,NSLocalizedDescription的值爲「請求超時」和NSUnderlyingError,並且該值沒有字符串。我將更新問題以包含這些錯誤字符串。 – Tiddly