【问题标题】:Javascript Call Nusoap WSJavascript 调用 Nusoap WS
【发布时间】:2017-10-24 19:29:21
【问题描述】:

我是 PHP 和 PHP WS 的新手,我的 porpouse 是将图像上传到具有 GUID 名称的临时文件,并使用它与 Cordova 和 Facebook 插件的一些社交媒体分享

我有这个 WS,我试图通过 Ajax 调用它,但仍然给我这个错误:

此服务的 WSDL 中未定义操作 '',目标是上传图像(WS 工作正常,我用 SoapUI 测试过)并很好地上传图像。

SERVER.PHP

            <?php
            error_reporting(0);  
            require_once('config/nusoap.php');
            $server = new soap_server();

            $server->configureWSDL('File Transfer Using Nusoap', 'urn:fileTransferwsdl');

            $server->register('transfer_file',                                                             
                array('filename' => 'xsd:string','fileAsEndcodedString' => 'xsd:string'),
                array('return' => 'xsd:string'),
                'urn:fileTransferwsdl',                                                                 
                'urn:fileTransferwsdl#transferFile',
                'rpc',
                'encoded',
                'Transfer any file using web service'
            );
            // Define the method as a PHP function
            function transfer_file($pFilename,$pEncodedString) {                           
                        $decodedData=base64_decode($pEncodedString);
                        $fp = fopen("uplodedimages/".$pFilename, 'w');
                        fwrite($fp, $decodedData);
                        fclose($fp);
                        return 'Your file is transfer to server successfully file name is -, ' . $pFilename;
            }


            // Use the request to (try to) invoke the service
            $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
            $server->service($HTTP_RAW_POST_DATA);
            $server->register("transfer_file");
            //$server->service(file_get_contents("php://input"));
            ?> 

AJAX 方法

    var soapRequest;
    try {
        soapRequest = "<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:urn='urn:fileTransferwsdl'>< soapenv:Header/>< soapenv:Body><urn:transfer_file soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><filename xsi:type='xsd:string'>" + filename + "</filename><fileAsEndcodedString xsi:type='xsd:string'>" + fileasString + "</fileAsEndcodedString></urn: transfer_file ></soapenv: Body ></soapenv: Envelope >";
        console.log("callWS2");

        $.ajax({
            type: "POST",
            url: wsUrl, //http://localhost/server.php
            contentType: "xml",
            dataType: "xml",
            data: soapRequest,
            success: succeeded,
            error: queryError
        });

请求错误还是 ContentType 错误?感谢您的帮助

【问题讨论】:

标签: javascript php ajax web-services cordova


【解决方案1】:

经过一番挖掘,我发现了问题。

第一个:请求有一些空格

2sd:我发现 Content-Security-Policy 存在连接问题,因此我添加了此异常:default-src 'self' data: gap: https://ssl.gstatic.com http://myWebserviceSite.com/;

3rd:将这个contentType:“xml”,dataType:“xml”改成这个contentType:“text/xml”,dataType:“text/xml”;

并且正在使用cordova和浏览器=)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2012-09-20
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多