加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice and soap ios

发布时间:2020-12-17 00:37:14 所属栏目:安全 来源:网络整理
导读:第一种方式: ??? //构建http请求对象 ??? NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; ?? ? ??? //以下对请求信息添加属性前四句是必有的,第五句是soap信息。 ?? ?[theRequest addValue: @"text/xml; charset=utf-8" fo

第一种方式:

??? //构建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]; ??? }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读