2

我正在尝试通过使用 SOAP 的代理连接到 Web 服务。问题是我不能使用 cURL,也不能添加任何模块来使这个 SOAP 消息更容易编写,我必须手动为消息创建 XML 并通过我的代理发送它。好消息是我实际上能够建立与 Web 服务的连接,唯一的问题是我收到的每个回复都说:“空消息 - 未收到数据”。谁能看到我的套接字在通过 XML 发送时做错了什么:

/*this is just striped of personal info, 
the XML I'm actually using is valid since 
on my development environment (which has cURL) 
will successfully get results with this XML*/

$request  = '<soapenv:Envelope>';
$request .= '<soapenv:Header>';
$request .=     '</soapenv:Header>';
$request .=     '<soapenv:Body>';
$request .=     '</soapenv:Body>';
$request .= '</soapenv:Envelope>';

$fp = fsockopen($proxy, 80, $errno, $errstr, 100);
if (!$fp) {
    echo "$errstr ($errno)<br />\r\n";
} else {
    $out  = "POST " . $path . " HTTP/1.1\r\n";
    $out .= "Host: " . $host . "\r\n";
    $out .= "Content-Length: " . strlen($request) . "\r\n";
    $out .= "Content-Type: text/xml; charset=utf-8\r\n";
    $out .= "SOAPAction: \"XXXXXXXXXXXXXX\"\r\n";
    $out .= "Accept: text/xml\n";
    $out .= "Proxy-Authorization: Basic $auth\r\n"; 
    $out .= "Connection: close\r\n\r\n";
    $out .= $request;
    $output = '';
    fwrite($fp, $out);
    while (!feof($fp)) {
        $output .= fgets($fp);
    }
    fclose($fp);
}
$output = trim(substr($output, strpos($output, "<?")));
print_r($output);
4

1 回答 1

0

我在 Java 中使用了一些 HTTP,这可以帮助你。标题字段由 CRLF "\r\n" 分隔:

..

$out  = "POST " . $path . " HTTP/1.1\r\n";
$out .= "Host: " . $host . "\r\n";

..

于 2013-08-27T13:39:42.963 回答