本帖最后由 manwuji 于 2010-10-09 10:43:06 编辑

解决方案 »

  1.   

    用用soapui,很方便,我是喜欢这种方式,讨厌使用soapclient或者nusoap,不够直接。以下是soapui根据你的wsdl文件实例化好的请求格式,举getAPmoney方法为例子POST http://58.53.194.80/swdx/services/APService HTTP/1.1
    Connection: close
    Accept-Encoding: gzip,deflate
    Content-Type: text/xml;charset=UTF-8
    SOAPAction: ""
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: 58.53.194.80
    Content-Length: 889<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://Endpoint.webservice.swdxsms.com">
       <soapenv:Header/>
       <soapenv:Body>
          <end:getAPmoney soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <compcode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">a</compcode>
             <account xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">b</account>
             <APName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">c</APName>
             <APPassword xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">d</APPassword>
          </end:getAPmoney>
       </soapenv:Body>
    </soapenv:Envelope>
    http 头和body都有了,你用curl模拟个post请求即可以下是返回的头和bodyHTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Content-Type: text/xml;charset=utf-8
    Date: Sat, 09 Oct 2010 05:05:36 GMT
    Connection: close<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:getAPmoneyResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://Endpoint.webservice.swdxsms.com"><getAPmoneyReturn xsi:type="soapenc:string" xsi:nil="true" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/></ns1:getAPmoneyResponse></soapenv:Body></soapenv:Envelope>
      

  2.   

    对于二楼的说法不是很明白,我找到一个这个,名位帮帮,看看二楼的办法,可以通过调用这个自定义函数来实现吗?function vpost($url,$data){ // 模拟提交数据函数   
      $curl = curl_init(); // 启动一个CURL会话   
      curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址   
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查   
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在   
      curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器   
      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转   
      curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer   
      curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求   
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包   
      curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // 读取上面所储存的Cookie信息   
      curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环   
      curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容   
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回   
      $tmpInfo = curl_exec($curl); // 执行操作   
      if (curl_errno($curl)) {   
      echo 'Errno'.curl_error($curl);   
      }   
      curl_close($curl); // 关键CURL会话   
      return $tmpInfo; // 返回数据   
    }  
      

  3.   

    webservice就请求端来说,其实就是一个http POST请求,只不过POST的http body不是平常我们form表单提交的那种(就是a=1&b=2&c=3那种),而是一个xml格式化串.
      

  4.   

    不太熟悉http吗?,如果是建议google复习一下先.$postString = <<<httpbody
    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://Endpoint.webservice.swdxsms.com">
       <soapenv:Header/>
       <soapenv:Body>
          <end:getAPmoney soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <compcode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">a</compcode>
             <account xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">b</account>
             <APName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">c</APName>
             <APPassword xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">d</APPassword>
          </end:getAPmoney>
       </soapenv:Body>
    </soapenv:Envelope>
    httpbody;
    $curl = curl_init('http://58.53.194.80/swdx/services/APService');
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-type:text/xml','SOAPAction:""'));
    $return = curl_exec($curl);
    curl_close($curl);
    echo $return;
      

  5.   

    以下代码对吗?调试时返回网页错误。不知道哪里写的不对。<?
    echo web_post("http://58.53.194.80/swdx/services/APService?wsdl","a=1")
    function web_post($url,$bm)
    {
    //准备工作开始
    if ($bm!=1){
    $a=iconv_substr($url,strpos($url,'?')+1,iconv_strlen($url,'gbk'),'gbk');
    $url=iconv_substr($url,0,strpos($url,'?')+1,'gbk');
    }
    else
    {
    $a=iconv_substr($url,strpos($url,'?')+1,iconv_strlen($url,'utf-8'),'utf-8');
    $url=iconv_substr($url,0,strpos($url,'?')+1,'utf-8');
    }//准备工作结束 $row = parse_url($url);
    $host = $row['host'];
    $port = $row['port'] ? $row['port']:80;
    $file = $row['path']; $len = strlen($a);
    $fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
    if (!$fp) {
    return "$errstr ($errno)\n";
    } else {
    $receive = '';
    $out = "POST $file HTTP/1.1\r\n";
    $out .= "User-Agent: Jakarta Commons-HttpClient/3.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "Content-type: text/xml;charset=UTF-8\r\n";
    $out .= "Connection: Close\r\n";
    $out .= "Content-Length: $len\r\n\r\n";
    $out .= "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:end=\"http://Endpoint.webservice.swdxsms.com\">\r\n  <soapenv:Header/>
       <soapenv:Body>\r\n      <end:getAPmoney soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n         <compcode xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">a</compcode>\r\n         <account xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">b</account>\r\n         <APName xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">c</APName>\r\n         <APPassword xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">d</APPassword>\r\n      </end:getAPmoney>\r\n</soapenv:Body>\r\n</soapenv:Envelope>\r\n";
    $out .= $a;
    fwrite($fp, $out);
    while (!feof($fp)) {
    $receive .= fgets($fp, 128);
    }
    fclose($fp);
    $receive = explode("\r\n\r\n",$receive);
    unset($receive[0]);
    return implode("",$receive);
    }
    }?>
      

  6.   

    要加SOAPAction头,这个是服务器那边要求,没办法,注意Content-length头的值是http body的串长<?php
    //准备工作结束
    $postString = <<<httpbody
    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://Endpoint.webservice.swdxsms.com">
       <soapenv:Header/>
       <soapenv:Body>
          <end:getAPmoney soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <compcode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">a</compcode>
             <account xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">b</account>
             <APName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">c</APName>
             <APPassword xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">d</APPassword>
          </end:getAPmoney>
       </soapenv:Body>
    </soapenv:Envelope>
    httpbody;
    $url  = "http://58.53.194.80/swdx/services/APService";
        $row = parse_url($url);
        $host = $row['host'];
        $port = $row['port'] ? $row['port']:80;
        $file = $row['path'];    $len = strlen($postString);
        $fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
        if (!$fp) {
            return "$errstr ($errno)\n";
        } else {
            $receive = '';
            $out = "POST $file HTTP/1.1\r\n";
            $out .= "User-Agent: Jakarta Commons-HttpClient/3.1\r\n";
            $out .= "Host: $host\r\n";
            $out .= "Content-type: text/xml;charset=UTF-8\r\n";
            $out .= "SOAPAction:''\r\n";
            $out .= "Connection: Close\r\n";
            $out .= "Content-Length: $len\r\n\r\n";
            $out .= $postString;
            fwrite($fp, $out);
            while (!feof($fp)) {
                $receive .= fgets($fp, 128);
            }
            fclose($fp);
            $receive = explode("\r\n\r\n",$receive);
            unset($receive[0]);
            echo htmlspecialchars($receive[1]);
        }
    ?>