代码之家  ›  专栏  ›  技术社区  ›  Mike Crittenden

使用SOAP和PHP获取PDF文件

  •  1
  • Mike Crittenden  · 技术社区  · 15 年前

    编辑:此问题无效,因为我使用的服务器突然过期。请忽略

    我对PHP中的soapclient不熟悉,我尝试通过传递三个参数并获取结果来获取PDF。这是我正在使用的WSDL文件(我对这部分没有太多/任何控制权):

    <!-- this WSDL file was automatically generated by 4D --> 
    <definitions name="A_WebService" targetNamespace="http://www.4d.com/namespace/default" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.4d.com/namespace/default" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
        <message name="WS_ME_StatementRequest"> 
            <part name="FuneralHomeID" type="xsd:string"/> 
            <part name="Month" type="xsd:int"/> 
            <part name="Year" type="xsd:string"/> 
        </message> 
        <message name="WS_ME_StatementResponse"> 
            <part name="StatementPDF" type="xsd:base64Binary"/> 
        </message> 
        <portType name="A_WebServiceRPC"> 
            <operation name="WS_ME_Statement"> 
                <input message="tns:WS_ME_StatementRequest"/> 
                <output message="tns:WS_ME_StatementResponse"/> 
            </operation> 
        </portType> 
        <binding name="A_WebServiceBinding" type="tns:A_WebServiceRPC"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" /> 
            <operation name="WS_ME_Statement"> 
    <documentation>Inputs: None
    Outputs: text variable</documentation> 
                <soap:operation soapAction="A_WebService#WS_ME_Statement"/> 
                <input> 
                    <soap:body use="encoded" namespace="http://www.4d.com/namespace/default" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
                </input> 
                <output> 
                    <soap:body use="encoded" namespace="http://www.4d.com/namespace/default" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
                </output> 
            </operation> 
        </binding> 
        <service name="A_WebService"> 
            <documentation></documentation> 
            <port name="A_WebServicePort" binding="tns:A_WebServiceBinding"> 
                <soap:address location="http://69.128.94.30:8080/4DSOAP/"/> 
            </port> 
        </service> 
    </definitions> 
    

    到目前为止,我已经有了一些只返回404的内容:

    <?php 
    
    header("content-type: application/pdf");
    
    $client = new SoapClient('http://69.128.94.30:8080/4DSOAP/');
    $result = $client->WS_ME_StatementRequest(array('FuneralHomeID' => '0008-00', 'Month' => 11, 'Year' => "2008"));
    $pdfdoc = $result->WS_ME_StatementResponse->StatementPDF;
    print($pdfdoc);
    

    对我做错什么有什么想法?

    3 回复  |  直到 15 年前
        1
  •  1
  •   Kieran Allen    15 年前

    看起来它是base64编码的。

    header("content-type: application/pdf");
    
    $client = new SoapClient('http://69.128.94.30:8080/4DSOAP/');
    $result = $client->WS_ME_StatementRequest(array('FuneralHomeID' => '0008-00', 'Month' => 11, 'Year' => "2008"));
    echo base64_decode($result->WS_ME_StatementResponse->StatementPDF);
    
        2
  •  1
  •   Fosco    15 年前

    乍一看,似乎soapclient URL是错误的。尝试:

    $client = new SoapClient('http://69.128.94.30:8080/4DSOAP/'); 
    
        3
  •  1
  •   Jarrod Nettles    15 年前

    我无法对此进行测试,因为我无法访问您的Web服务(将其粘贴到您的浏览器中,并显示其已过期),但我相信您需要在邮件头中指定内容长度和处置方式。

    $length = strlen($pdfdoc);
    header("Content-type: application/pdf");
    header("Content-Length: $length");
    header("Content-Disposition: attachment; filename=myfile.pdf");
    
    推荐文章