(转自http://blog.sina.com.cn/s/blog_667126df01014h10.html)
-(void)postData{
NSString * urlStr = [NSString stringWithFormat:@"xxxxxxxxxxx"];
NSURL * url = [NSURL URLWithString:urlStr];
NSString *body = [NSString stringWithFormat:@"A=%@&B=%@&C=%@&D=%@",strA,strB,strC,strD];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[body dataUsingEncoding: NSASCIIStringEncoding]];
NSURLConnection *theConnection=[[[NSURLConnection alloc] initWithRequest:request delegate:self]autorelease];
if (theConnection) {
self.mutabledata=[[NSMutableData data] retain];//如果链接上了
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.mutabledata appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"postData finished");
}