2014-01-19 130 views
0

我想發佈到一個工作註冊表格,在php中使用了usercake,我試圖按下按鈕時向註冊文件發出發佈請求。然而沒有任何反應我相信我的措辭是錯的。這是我目前的代碼。AFNetworking API無法發佈到服務器

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://thissite.co/"]]; 
    [httpClient setParameterEncoding:AFFormURLParameterEncoding]; 
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" 
                  path:@"http://thissite.co/cake/register.php?" 
                 parameters:@{@"username":@"testingService", @"displayname":@"testingService", @"password":@"thisismypassword", @"passwordc":@"thisismypassword", @"email":@"[email protected]", @"bio":@"I am this amazing bio", @"skills":@"hackingthissuckerfromaframework", @"interests":@"I like to hack", @"skills_needed":@"php anyone", @"company":@"Noneofyourtesting", @"dob":@"nopeeeee", @"occupation":@"noob"}]; 

} 

回答

0

看起來您並未執行您創建的請求。嘗試在方法結尾處添加此代碼。

AFHTTPRequestOperation * httpOperation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    //success code 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    //error handler 
}]; 
[httpClient enqueueHTTPRequestOperation:httpOperation]; 

或者有更簡單的方法

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://thissite.co/"]]; 
[httpClient setParameterEncoding:AFFormURLParameterEncoding]; 
[httpClient postPath:@"cake/register.php" parameters:@{@"username":@"testingService", ...} success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    //success code 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    //error handler 
}]; 
+0

你是最棒的!我只是學習ios和xcode。 – JohnnyWineShirt

相關問題