ASIHttprequest NSMutableURLRequest post请求的方便之处
来源:互联网 发布:美食文案 知乎 编辑:程序博客网 时间:2024/05/20 17:09
如果是NSMutableURLRequest 要在请求加入各种字段 其中包括
NSMutableURLRequest *request =[NSMutableURLRequestrequestWithURL:[NSURLURLWithString:URL]];
//设置发送请求的方式
[request setHTTPMethod:@"POST"];
//设置请求体
[request addValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"Content-type"];
//设置参数
NSString *body =[NSStringstringWithFormat:@"username=%@&password=%@&email=%@",UsernameTextField.text,PasswordTextField.text,emailTextField.text];
//计算参数的总长度
int length =[bodylengthOfBytesUsingEncoding:NSUTF8StringEncoding];
//添加字段 Content-Lenth该字段的大小事参数集合的总长度 和URL没有关系
[request addValue:[NSStringstringWithFormat:@"%d",length]forHTTPHeaderField:@"Content-Length"];
NSData *data =[bodydataUsingEncoding:NSUTF8StringEncoding];
//设置请求体
[request setHTTPBody:data];
//发送请求
_connection =[[NSURLConnectionalloc]initWithRequest:requestdelegate:self];
如果是ASIHTTP的话直接使用
ASIFormDataRequest *request1 =[ASIFormDataRequestrequestWithURL:[NSURLURLWithString:@"http://119.255.38.178:8089/sns/my/login.php"]];
request1.delegate=self;
//Key 是来自开发文档
[request1 addPostValue:@"test"forKey:@"username"];
[request1 addPostValue:@"123456"forKey:@"password"];
[request1 startAsynchronous];
- ASIHttprequest NSMutableURLRequest post请求的方便之处
- NSMutableURLRequest实现Post请求
- IOS成长之路-NSMutableURLRequest实现Post请求
- NSMutableURLRequest 请求头的设置
- NSMutableURLRequest POST
- NSMutableURLRequest请求
- 登陆请求(post),利用ASIHTTPRequest;
- iOS之NSURLRequest NSMutableURLRequest 数据请求
- NSMutableURLRequest实现Post请求及其timeoutInterval不生效问题解决
- NSMutableURLRequest实现Post访问
- unsupported URL NSMutableURLRequest post
- NSMutableURLRequest post提交参数
- ASIHTTPRequest 对GET POST 请求简单封装
- POST上传文件之分类抽取——以后只需要把分类导入,使用NSMutableURLRequest的分类即可
- IOS网络请求之ASIHTTPRequest
- ASIHttpRequest POST方式的实现
- 用ASIHttpRequest通过post请求给java服务器上传的代码(不会出现乱码)
- ASIHTTPRequest实现对PUT,DELETE,POST,GET请求方式的处理
- 再谈协方差矩阵之主成分分析
- gpg: Can't check signature: public key not found错误的解决方法
- HDU 1.1.2 A+B for Input-Output Practice (II)
- ehcache
- 关于maven的配置文件pom.xml中<classifier>jdk15</classifier>在gradle中的表达问题
- ASIHttprequest NSMutableURLRequest post请求的方便之处
- 第十一周项目二 求最大公约数
- GDB常用命令
- 最值得学习阅读的10个C语言开源项目代码
- Android平台体系结构中的虚拟机Dalvik与JAVA中的虚拟机有什么不同
- iPad : 使用UIPopoverController弹窗支持拍照效果
- JavaScript prototype背后的工作原理
- HDU 1.1.3 A+B for Input-Output Practice (III)
- 第十一周项目二——输出四个数的最大公约数