发布SOAP XML请求

时间:2017-09-01 19:39:29

标签: php soap

我从这里尝试了几个例子,但似乎没有什么对我有用。

我需要为请求发送此信封:

 render() {
 return (
   <MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}>
    <div>
     <AppBar
       title = { "Test 1" }
       onLeftIconButtonTouchTap = { this.handleTouchMap.bind(this) }
     />
     <LeftDrawer open={this.state.open} />
    </div>
   </MuiThemeProvider>  
 );}

这是我的代码:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:v2="http://xmlns.oracle.com/oxp/service/v2">
  <soapenv:Header />
 <soapenv:Body>
  <v2:runReport>
  <v2:reportRequest>
  <v2:attributeLocale>en-US</v2:attributeLocale>
  <v2:attributeTemplate>Default</v2:attributeTemplate>
  <v2:reportAbsolutePath>/Custom/Financials/Fac/XXIASA_FAC.xdo</v2:reportAbsolutePath>
  <v2:dynamicDataSource xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  <v2:parameterNameValues xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  <v2:XDOPropertyList xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </v2:reportRequest>
  <v2:userID>user</v2:userID>
  <v2:password>password</v2:password>
  </v2:runReport>
  </soapenv:Body>
  </soapenv:Envelope>

这是我回来的奇怪结果:

  $url = 'https://soapurl/v2/ReportService?WSDL';

    $headers = array("Content-type: application/soap+xml; charset=\"utf-8\"", "Content-length: " . strlen($xml));

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    print_r($response);

为什么我得到这个?

1 个答案:

答案 0 :(得分:1)

如果您使用网络嗅探器(我会推荐Wireshark),您会看到数据已被压缩。这通常用于服务器端以减少所需的带宽。每个现代浏览器都会自动解压缩,但应用程序的卷曲却不会自动解压缩。如果您将该字符串保存在文件(例如response.bin上)并运行file response.bin,您将看到使用的压缩算法(可能是gzip或deflate)。

要解决此问题,请让curl为您解压缩响应:

curl_setopt($ch,CURLOPT_ENCODING, '');