zoukankan      html  css  js  c++  java
  • iOS开发中的Get请求和POST请求

    //Get请求一般为不涉及到用户的账号密码的网络请求,其中Get请求是等请求内容回来之后,才可以进行下一步的操作

    - (void)requestWithGet{

        //Get请求:

        

        //1.设置请求路径

        NSString * urlStr = [NSString stringWithFormat:@"http://192.168.1.53:8080/MJServer/login?username=%@&pwd=%@",self.nameTextField.text,self.pawTextField.text];

        //2.创建请求对象,不设置,默认为Get

        NSURL * url = [NSURL URLWithString:urlStr];

        //3.发送请求

    }

    //POST请求可以用来发送账号密码的登录请求,因为其URL没有显示账号和密码的内容,所以要相对安全些,而且一些图片的异步下载等等

    - (void)requestWithPOST{

        //POST请求:

        

        //设置请求路径

        NSURL * url = [NSURL URLWithString:@"http://192.168.1.53:8080/"];

        //创建请求对象

        NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];

        //设置请求超时为5秒

        request.timeoutInterval=5.0;

        //设置请求方法

        request.HTTPMethod=@"POST";

        //设置请求体

        NSString *param=[NSString stringWithFormat:@"username=%@&pwd=%@",self.nameTextField.text,self.pawTextField.text];

        //把拼接后的字符串转换为data,设置请求体

        request.HTTPBody=[param dataUsingEncoding:NSUTF8StringEncoding];

        //发送请求

        

        

    }

  • 相关阅读:
    谷歌三架马车之 The Google File System 中文版
    数据集市 Data Mart
    VMware虚拟机ubuntu下安装VMware Tools步骤
    NOIP普及组 海港 题解
    HXD的DS
    离散化
    哈希表
    状态压缩DP 初探
    《信息学奥赛一本通》大盗阿福 题解
    NOIP 加工零件 题解
  • 原文地址:https://www.cnblogs.com/zhouyantongiOSDev/p/4244320.html
Copyright © 2011-2022 走看看