所以我试图通过带有参数的 url 将数据发送到 web 服务。我的代码在下面,但它永远不会到达服务器。请求和响应为空。我究竟做错了什么?
-(void) postData:(NSString *)data{
NSURLResponse* response;
NSError* error = nil;
NSString *urlString = [NSString stringWithFormat:@"http://someaddress.com/api?data=%@", data];
NSURL *lookupURL = [NSURL URLWithString:urlString];
//Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:lookupURL];
NSData *request = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *dataString = [[NSString alloc] initWithData:request encoding:NSUTF8StringEncoding];
NSLog(@"-----------------------------");
NSLog(@"Request: %@", theRequest);
NSLog(@"req response: %@", request);
NSLog(@"response: %@", dataString);}