参数是字典的post请求
NSURL *url = [NSURL URLWithString:@"http://192.168.88.8/app/qianfeng/ichat/register.php”];
//客户端类型 iphone ipad
NSString *clientType = [[UIDevice currentDevice] model];
//设备标示
NSString *udid = [[UIDevice currentDevice] uniqueDeviceIdentifier];
//参数字典
NSDictionary *dic = @{@"Name":@"bubiqudong",
@"Password":@"123456",
@"Email":@"xiao@qq.com",
@"Age":@"10",
@"Sex":@"女",
@"Description":@"带着灵魂",
@"ClientType":clientType,
@"DeviceIdentifier":udid,
@"Address":@"旅行"};
//字典转成data
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:0 error:nil];
//asi
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.delegate = self;
request.tag = 1;
//请求类型
[request setRequestMethod:@"POST"];
//请求头
[request addRequestHeader:@"Content-Type" value:@"Application/x-www-form-data"];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",jsonData.length]];
//请求体
[request setPostBody:[NSMutableData dataWithData:jsonData]];
//开始请求
[request startAsynchronous];
参数是标准的XML的post请求
/*
<root>
<Position>
<IP>192.168.11.32</IP>
<Longitude>45.222122</Longitude>
<Latitude>116.22222</Latitude>
</Position>
<Password>123456</Password>
<Name>oyangjian</Name>
<Status>hidden</Status>
</root>
*/
GDataXMLElement *IPEle = [GDataXMLElement elementWithName:@"IP" stringValue:@"192.168.11.32"];
GDataXMLElement *LongitudeEle = [GDataXMLElement elementWithName:@"Longitude" stringValue:@"45.222122"];
GDataXMLElement *latitudeELe = [GDataXMLElement elementWithName:@"Latitude" stringValue:@"116.22222"];
GDataXMLElement *positionEle = [GDataXMLElement elementWithName:@"Position"];
[positionEle addChild:IPEle];
[positionEle addChild:LongitudeEle];
[positionEle addChild:latitudeELe];
GDataXMLElement *passwordEle = [GDataXMLElement elementWithName:@"Password" stringValue:@"123456"];
GDataXMLElement *nameEle = [GDataXMLElement elementWithName:@"Name" stringValue:@"bubiqudong"];
GDataXMLElement *statusEle = [GDataXMLElement elementWithName:@"Status" stringValue:@"hidden"];
GDataXMLElement *rootEle = [GDataXMLElement elementWithName:@"root"];
[rootEle addChild:positionEle];
[rootEle addChild:passwordEle];
[rootEle addChild:nameEle];
[rootEle addChild:statusEle];
//xmlString -> xmlData
NSData *xmlData = [rootEle.XMLString dataUsingEncoding:NSUTF8StringEncoding];
//创建请求
NSURL *url = [NSURL URLWithString:@"http://192.168.88.8/app/qianfeng/ichat/login.php"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.delegate = self;
request.tag = 2;
//请求方式
[request setRequestMethod:@"POST"];
//请求头
[request addRequestHeader:@"Content-Type" value:@"Application/x-www-form-data"];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",xmlData.length]];
//请求体
[request setPostBody:[NSMutableData dataWithData:xmlData]];
//开始请求
[request startAsynchronous];
// NSURL *url = [NSURL URLWithString:@"http://192.168.88.8/app/qianfeng/ichat/upload_headimg.php"];
UIImage *img = [UIImage imageNamed:@"2_10.jgp"];
NSData *imgData = UIImageJPEGRepresentation(img, 1);
//base64编码
NSString *imgStr = [GTMBase64 stringByEncodingData:imgData];
/*
<root>
<Token>NTM0Km95YW5namlhbjIyKjEyMzQ1NioxMzcyNTk2MTEx</Token> <HeadImage>iVBORw0KGgoAAAANSUhEUg
...AAAiYAAAGcCAIAAABiFfyfAAAAHGlET1QA </HeadImage>!
<ImageType>image/png</ImageType>
</root>
*/
GDataXMLElement *tokenEle = [GDataXMLElement elementWithName:@"Token" stringValue:self.token];
GDataXMLElement *headimageEle = [GDataXMLElement elementWithName:@"HeadImage" stringValue:imgStr];
GDataXMLElement *imageTypeEle = [GDataXMLElement elementWithName:@"ImageType" stringValue:@"image/jpg"];
GDataXMLElement *rootEle = [GDataXMLElement elementWithName:@"root"];
[rootEle addChild:tokenEle];
[rootEle addChild:headimageEle];
[rootEle addChild:imageTypeEle];
PKDownload *download = [[PKDownload alloc] initWithURL:@"http://192.168.88.8/app/qianfeng/ichat/upload_headimg.php" Delegate:self];
[download startPostWithJsonOrXmlString:rootEle.XMLString];
NSURL *url = [NSURL URLWithString:@"http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//设置请求方式
[request setHTTPMethod:@"POST"];
// @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
// @"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
// @" <soap12:Body>"
// @" <getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
// @" <theCityName>"
// @"_textField.text"
// @" </theCityName>"
// @" </getWeatherbyCityName>"
// @" </soap12:Body>"
// @" </soap12:Envelope>";
NSString *str = [NSString stringWithFormat:@"%@%@%@",@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
@"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
@" <soap12:Body>"
@" <getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
@" <theCityName>",_textField.text,@" </theCityName>"
@" </getWeatherbyCityName>"
@" </soap12:Body>"
@" </soap12:Envelope>"];
NSData *xmlData = [str dataUsingEncoding:NSUTF8StringEncoding];
//请求头
[request setValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",xmlData.length] forHTTPHeaderField:@"Content-Length"];
//请求体
[request setHTTPBody:xmlData];
[NSURLConnection connectionWithRequest:request delegate:self];