NSMutableURLRequest POST

简介: NSMutableURLRequest POST
-(NSString *)GetReturnFromPost:(NSString*)urlStr  postData:(NSString*)_postData
{
    NSData *postData = [_postData dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlStr]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    //[NSURLConnection connectionWithRequest:request delegate:self ];
    //同步请求的的代码
    //returnData就是返回得到的数据
    NSData *returnData =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    return [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
}
相关文章
|
8月前
|
缓存 前端开发 API
GET 和 POST
GET 和 POST
|
11月前
|
网络协议 安全 数据安全/隐私保护
GET与POST的区别
GET与POST的区别
99 0
|
11月前
|
缓存 安全 数据库
【探索】Get与Post
Http,url,get,post的关系:Http协议通过定义get post等请求,对url地址描述的资源进行增删改查。
|
11月前
|
XML JSON 编解码
POST 怎么样用
POST 怎么样用
|
网络协议 安全
GET 和 POST 的区别
GET 和 POST 的区别
104 0
NSMutableURLRequest实现Post访问
NSMutableURLRequest实现Post访问
61 0
|
网络协议
get和post区别是什么?
get和post区别是什么?
149 0
|
缓存 前端开发 数据库
Ajax的get与post的区别,什么时候使用post?
Ajax的get与post的区别,什么时候使用post?
127 0
POST 与 GET
什么是 HTTP? 超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信。 HTTP 的工作方式是客户机与服务器之间的请求-应答协议。
656 0
|
Web App开发 网络协议
总结get和post区别
总结get和post区别---面试用 get参数通过url传递,post放在request body中。 get请求在url中传递的参数是有长度限制的,而post没有。
1131 0