這是我的JSON字典如何調用在IOS PUT請求,並需要通過一個字典
{"pid":"14982","type":"intervention","uid":"10008","bookmark_g7l03":{"und":[{"value":"S:1","format":"null","safe_value":"S:1"}]}}
我需要PUT請求傳遞到以下網址
http://example.com/services/profiles/pid
讓我們知道如何要通過字典來Webservice的URL在IOS
NSString *data = [NSString stringWithFormat:@"{\"pid\":\"%@\",\"type\":\"%@\",\"uid\":\"%@\",\"%@\":{\"und\":\[{\"value\":\"%@\",\"format\":\"null\",\"safe_value\":\"\%@\"}]}}",pid,type, uidNo,bkMarkStr,self.startString,self.startString];
NSURL *bkMrkUrl = [NSURL URLWithString:@"http://example.com/services/profiles/pid=14997"];
NSData *postData = [data dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *bkMrkReq = [[NSMutableURLRequest alloc]initWithURL:bkMrkUrl];
[bkMrkReq setHTTPMethod:@"PUT"];
[bkMrkReq setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[bkMrkReq setHTTPBody:postData];
[NSURLConnection sendAsynchronousRequest:bkMrkReq queue:[NSOperationQueue currentQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *txt = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"data....:%@",txt);
// handle response here
}];
在這裏,當我打印的文本數據
輸出是:<?xml version="1.0" encoding="utf-8"?> <result>CSRF validation failed</result>
我應該做的與數據.. 這裏正在更新在服務器領域的信息。
結帳AFNetworking http://afnetworking.com/ – user623396 2015-03-25 08:50:07