将数组发送到服务器而不使用post service附加到url

时间:2015-06-24 07:07:08

标签: php objective-c post

您好我正在尝试将数组发送到服务器而不将其附加到网址,但它没有发生。

 NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
[dict setObject:@"Kiran" forKey:@"name"];
[dict setObject:@"kumar" forKey:@"lName"];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://192.168.0.125/vblive_new/api/getMobileContactList?"]];

[request setHTTPMethod:@"POST"];

NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];
[jsonDict setValue:dict forKey:@"userName"];
NSLog(@"JSON Dict: %@",jsonDict);//Check your array here...


NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]];
NSLog(@"JSON String: %@",jsonString); //Check your post String here...
NSLog(@"post length is %@",postLength);
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"json" forHTTPHeaderField:@"Data-Type"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:jsonData];

conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:true];

0 个答案:

没有答案