无标题文章

//Get 服务器连接地址
#define TEST_URL @"http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=%@&userID="

//Post 服务器连接地址
#define POST_URL @"http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo"
@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
 
}



//get请求
- (IBAction)Get:(id)sender
{
    //1.连接字符串
    NSString *str1=[NSString stringWithFormat: TEST_URL,self.myNumberTF.text];
    
    //2.拿到URL 字符串
    NSURL *url= [NSURL URLWithString:str1];
    
    //3.将连接封装成 请求对象
    NSURLRequest *quest=[[NSURLRequest alloc]initWithURL:url];
    //4.Get 请求代理
    NSData *data=[NSURLConnection sendSynchronousRequest:quest returningResponse:nil error:nil];
    //5.返回数据到Textviewd<展示信息>
    self.JieGuoTextfield.text=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
}

//Post请求
- (IBAction)Post:(id)sender
{
    //1.创建URL 地址
    NSURL *url =[NSURL URLWithString:POST_URL];
    
    NSMutableURLRequest*requst=[[NSMutableURLRequest alloc]initWithURL:url];
    
    [requst setHTTPMethod:@"POST"];
    
    NSString *str=[NSString stringWithFormat:@"mobileCode=%@&userID=",self.myNumberTF.text];
    
    NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
    
    [requst setHTTPBody:data];
    
    NSData *myDatas =[NSURLConnection sendSynchronousRequest:requst returningResponse:nil error:nil];
    
    self.JieGuoTextfield.text =[[NSString alloc]initWithData:myDatas encoding:NSUTF8StringEncoding];
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容