![](/img/trans.png)
[英]How to make nusoap server with nusoap lib, and call using Javascript
[英]Javascript Call Nusoap WS
我是PHP和PHP WS的新手,我的豚鼠是使用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? 感谢您的帮助
经过一番挖掘,我发现了问题所在。
1:请求中有一些空格
2sd:我发现了Content-Security-Policy的连接问题,因此我添加了以下异常:default-src'self'数据:差距: https : //ssl.gstatic.com http://myWebserviceSite.com/ ;
第三:将内容类型:“ xml”,数据类型:“ xml”更改为该内容类型:“ text / xml”,数据类型:“ text / xml”;
并全部在cordova和浏览器上运行=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.