我想发送一个异步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