第一种方式:
//构建http请求对象
NSMutableuRLRequest *theRequest = [NSMutableuRLRequest requestWithURL:url];
//以下对请求信息添加属性前四句是必有的,第五句是soap信息。
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"www.example.org/services/VersionUpdate/getVersionInfo" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: [Nsstring stringWithFormat:@"%d",xmlstr.length] forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:data ];// [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
DMXProtocolFactory *haha = [[DMXProtocolFactory alloc]init];
//发送异步请求
// NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:haha];
//如果连接已经建好,则初始化data
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
// 發送同步請求,這裡得returnData就是返回得數據楽
NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:nil error:nil];
Nsstring *str = [[Nsstring alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
第二种方式:(用ASIFormDataRequest 或 ASIHTTPRequest 请求都可以 --- 但要配置好头信息)
// ASIFormDataRequest *reques = [[ASIFormDataRequest alloc]initWithURL:url]; ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url]; //设置ASIHTTPRequest代理 // request.delegate = aRequestModel.delegate; //设置协议请求类型 [request setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1],@"RequestType",nil]]; // 设置请求方式 [request setRequestMethod:@"POST"]; // 设置请求头 [request setRequestHeaders:[NSMutableDictionary dictionaryWithDictionary:[DMXProtocolInteractiveEngine commonHeader:xmlstr.length]]]; // 设置post的数据 [request setPostBody:data]; [request startSynchronous]; NSError *errors = [request error]; Nsstring *response = nil; if (!errors) { response = [request responseString]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。