zoukankan      html  css  js  c++  java
  • NSMutableURLRequest的Post请求

    NSData *bodyData = [[bodyString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]dataUsingEncoding:NSUTF8StringEncoding];//把bodyString转换为NSData数据  
    NSURL *serverUrl = [[NSURL URLWithString:RequestUrl] URLByAppendingPathComponent:urlStr];//获取到服务器的url地址  
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverUrl  
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData  
                                                       timeoutInterval:10];//请求这个地址, timeoutInterval:10 设置为10s超时:请求时间超过10s会被认为连接不上,连接超时  
      
    [request setHTTPMethod:@"POST"];//POST请求  
    [request setHTTPBody:bodyData];//body 数据  
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];//请求头  
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];//异步发送request,成功后会得到服务器返回的数据  
    //返回的数据 根据系统的不同会返回不同编码的数据,比如windows 为GBK,Ubuntu 为UTF8.。。  
    //注意转换编码格式 
    

      

  • 相关阅读:
    Jenkins的maven工程打包的时候怎么指定不同环境的配置文件
    杂记待整理
    zabbix监控网络的出入口流量
    MySQL的恢复脚本
    mysql 备份恢复图
    切割haproxy的日志
    zabbix 监控MySQL
    svn 的备份还原
    svn做目录访问控制(AuthzSVNAccessFile)
    MySQL多实例
  • 原文地址:https://www.cnblogs.com/wuwangchuxin/p/3806571.html
Copyright © 2011-2022 走看看