你好,我填寫了一個NSMutableArray
與字典,我需要郵寄發送到服務器(我使用AFNetworking
),但我得到<null>
響應,我如何發佈數組以獲得一個OK響應?下面我展示的代碼:發佈到服務器NSMutableArray與字典
NSDictionary *[email protected]{@"contacts":array};
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://www.angelpolitics.com"]];
[httpClient setDefaultHeader:@"Content-Type" value:@"application/json"];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
path:@"/mobile/ios_contact.php"
parameters:dict
];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
if (JSON !=nil) {
[SVProgressHUD dismiss];
NSLog(@"Result contacts %@",JSON);
if ([[JSON objectForKey:@"a"]isEqualToString:@"Ok"]) {
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Notification" message:@"Leads add succesfully" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertView show];
[self.delegate dismissController:self];
NSLog(@"Resulta AddLeads %@",JSON);
}
}else{
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Data do not send try again, please" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertView show];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"error %@", [error description]);
}];
operation.acceptableContentTypes=[NSSet setWithObjects:@"application/json",@"text/json",@"text/html", nil];
[queue addOperation:operation];
和數組是如下:
(
{
email = "N/A";
lastname = Doe;
name = John;
phone = "(555) 555-55";
},
{
email = "N/A";
lastname = Poppins;
name = Mary;
phone = "(333) 333-333";
},
{
email = "N/A";
lastname = Skywalker;
name = Luke;
phone = "(222) 222-2222";
}
)
服務器返回什麼代碼? – Miroslav