欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

objective-c使用post方式向服务器传数据,objective-cpost

来源: 开发者 投稿于  被查看 20680 次 评论:11

objective-c使用post方式向服务器传数据,objective-cpost


(转自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");

}


相关文章

    暂无相关文章

用户评论