apple watch网络请求

Apple Watch POST网络请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
NSURL *url = [NSURL URLWithString:@"http://testUrl.com:8080/wallet.html"];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];

NSString *bodyStr = [NSString stringWithFormat:@"xx=xx&xx=xx"];

NSData *bodyData = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:bodyData];

[request setValue:[NSString stringWithFormat:@"string"] forHTTPHeaderField:@"heardstring"];

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request

completionHandler:

^(NSData *data, NSURLResponse *response, NSError *error) {

NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

NSLog(@"解析到的数据 dic = %@",dic);
NSLog(@"解析到的数据 error = %@",error);
}];

//使用resume方法启动任务
[dataTask resume];