我消耗內搭參數這樣發送HTTP身體作爲使用AFNetworking或NSURLConnection的
jsonObj = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
一個POST網絡服務因此,如何把它的參數我使用AFNetworking消費web服務的字符串。
我的代碼
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager.requestSerializer setValue:ContentType forHTTPHeaderField:@"Content-Type"];
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0],@"id",[NSNumber numberWithInt:1],@"platform",API_HomeProductList,@"method", nil];
NSDictionary *param =[NSDictionary dictionaryWithObjectsAndKeys:dic,@"jsonObj", nil];
[manager POST:APIMainURL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableDictionary *json = [[NSMutableDictionary alloc]initWithDictionary:[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil]]; //
NSLog(@"JSON: %@",json);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}];
當我看到AFNetworking將其轉換成JSON後,我的參數,它成爲有效的JSON
{
"jsonObj" = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
}
,但我得到一些錯誤,導致我的網絡服務採取
jsonObj = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
作爲參數
所以,請建議我如何在參數發送
jsonObj = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
。
看到此鏈接可能是幫助你的http:// stackoverflow.com/questions/21344580/afnetworking-posts-json-arrays-as-multiple-single-entry-dictionaries –