首页 > 移动平台 > 详细

IOS http 请求

时间:2014-09-14 10:03:36      阅读:292      评论:0      收藏:0      [点我收藏+]

asihttprequest 为第三方数据请求,一下为get  和post 两种请求。

Get:

    NSString *loginName=@"Tony";

    NSString *pwd=@"123";

    NSString *postURL=[NSString stringWithFormat:@"http://192.168.2.2:1234/WebServiceDemo.asmx/LoginIn?loginName=%@&pwd=%@",loginName,pwd];

    NSLog(@"发送时请求URL%@",postURL);

    ASIHTTPRequest *request=[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:postURL]];

    [request setRequestMethod:@"GET"];

    [request startSynchronous];

    NSError *error=[request error];

    if(!error)

    {

        NSString *result=[request responseString];

        NSLog(result);

    }

Post :

//---------------Http Post-----------------------

    NSString *postUrl=[NSString stringWithFormat:@"http://192.168.2.2:1234/WebServiceDemo.asmx/GetInfo"];

    ASIFormDataRequest *request=[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:postUrl]];

    

    // 设置 post参数

    [request setPostValue:@"1233" forKey:@"LoginName"];

    [request setPostValue:@"dsadasdasd" forKey:@"pwd"];

    [request startSynchronous];

    

    NSString *result=[request responseString];

    NSLog(result);

    [result release];

    

 

IOS http 请求

原文:http://www.cnblogs.com/pengzhaov/p/3970698.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!