0
所以我試圖通過帶有參數的URL將數據發送到web服務。我有的代碼是在下面,但它從來沒有命中服務器。請求和響應爲空。我究竟做錯了什麼?Obj-C NSURLConnection不起作用
-(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);}
請更改標題,因爲它工作 – 2013-03-06 16:36:13
但是你的代碼做了一個GET沒有發佈+你不要編碼數據 – 2013-03-06 16:36:40