我想發送一個異步http請求到服務器(在我的情況下是django)。 出於某種原因,它調用didFailWithError方法 - 這意味着它不起作用。 這是我的代碼:iPhone - NSURL連接
responseData = [NSMutableData data];
baseURL = [NSURL URLWithString:@"http://localhost:8000/messages/views/new_messages/"];
NSURLRequest *request =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8000/messages/views/new_messages/"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
return TRUE;
}
,這些都是連接的方法:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength:0];
NSLog(@"part 1 works");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
NSLog(@"part 2 works");
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"error!!!");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"finish");
}
- 有什麼錯呢?
- 我糾正它後 - 我怎樣才能發送帖子參數通過這個服務器?
感謝
謝謝!這就是我一直在尋找的 – 2011-12-25 13:32:25