zoukankan      html  css  js  c++  java
  • iOS请求webservice

    (IBAction) webServicexRequestPost:(id)sender{

    //封装soap请求消息,构建webServices请求字符串

        NSString * soapMessage = [NSString stringWithFormat:@"<?xml version=/"1.0/" encoding=/"utf-8/"?>/n"

         "<soap:Envelope xmlns:xsi=/"http://www.w3.org/2001/XMLSchema-instance/" xmlns:xsd=/"http://www.w3.org/2001/XMLSchema/" xmlns:soap=/"http://schemas.xmlsoap.org/soap/envelope//">/n"

         "<soap:Body>/n"

         "<Test xmlns=/"http://jinlong.ctc.com/">/n"

         "<userID>%@</userID>/n"

         "</Test>/n"

         "</soap:Body>/n"

         "</soap:Envelope>/n",@"JINLONG"

       ];

       NSString * msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

        //设置请求地址

        NSURL * url = [NSURL URLWithString:@"http://localhost:8080/TestWebServices/services/Test"];  

        NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];

        //加请求头文件

        [urlRequest addValue@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

        [urlRequest addValue@"http://service.xiva.com/login" forHTTPHeaderField:@"SOAPAction"];

      [urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

        //设置请求方式

      [urlRequest setHTTPMethod:@"POST"];

        [urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

       NSURLResponse *reponse;

       NSError * error = nil;

        //接受返回数据

       NSData  * responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&reponse error:&error];

        NSMutableString * 

        result = [[NSMutableString allocinitWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"Return String is========>%@",result);  

    }

  • 相关阅读:
    错误 1324。文件夹路径 .. 中含有无效的字符
    linux下 tar解压 gz解压 bz2等各种解压文件使用方法
    取消EXCEL 2007/2010中邮箱地址的自动链接
    Windows2000/XP启动过程详解
    Ubuntu下安装apache2,mysql,php,wordpress.
    offcie2007,2010,2012中快速删除指定的页面.
    mysql连接,修改密码,增加用户,显示,导入导出
    键盘各按键的使用
    cvim 使用
    matlab基础知识(basic operation)
  • 原文地址:https://www.cnblogs.com/lsck/p/2534744.html
Copyright © 2011-2022 走看看