2013-08-28 74 views
2

我想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個按鍵?

+1

-1001通常意味着請求超時。你的網絡工作正常嗎? – tilo

+0

我們可以得到錯誤代碼的錯誤描述嗎?那麼嘗試與本地的'NSURLConnection'相同呢? –

+0

網絡應該正常工作。其他幾個應用程序正在使用它,並正常工作。我不知道如何使用NSURLConnection,我堅信在這個網絡編程的東西我的舒適區。錯誤返回了4個鍵,其中值爲myurl的NSErrorFailingURLStringKey,值爲<不是Objective-C對象的NSErrorFailingURLKey>,NSLocalizedDescription的值爲「請求超時」和NSUnderlyingError,並且該值沒有字符串。我將更新問題以包含這些錯誤字符串。 – Tiddly

回答

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

我該怎麼稱呼這個?我在哪裏可以找到/創建ASIHTTPRequest對象以傳遞給它? – Tiddly

+0

ASIHTTPRequest?請記住你正在使用的內容。 – Abizern

+0

該評論針對的是此後編輯的問題,因此評論沒有任何意義。我沒有使用ASIHTTPRequest,我在問這個問題,因爲它在答案中,我不明白。 – Tiddly

相關問題