如果是NSMutableURLRequest 要在请求加入各种字段 其中包括
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]];
//设置发送请求的方式
[request setHTTPMethod:@"POST"];
//设置请求体
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];
//设置参数
NSString *body =[NSString stringWithFormat:@"username=%@&password=%@&email=%@",UsernameTextField.text,PasswordTextField.text,emailTextField.text];
//计算参数的总长度
int length =[body lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
//添加字段 Content-Lenth 该字段的大小事参数集合的总长度 和URL没有关系
[request addValue:[NSString stringWithFormat:@"%d",length] forHTTPHeaderField:@"Content-Length"];
NSData *data =[body dataUsingEncoding:NSUTF8StringEncoding];
//设置请求体
[request setHTTPBody:data];
//发送请求
_connection =[[NSURLConnection alloc]initWithRequest:request delegate:self];
如果是ASIHTTP的话直接使用
ASIFormDataRequest *request1 =[ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"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];