【发布时间】: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 错误?感谢您的帮助
【问题讨论】:
-
认为您的 contentType 错误 - 看起来应该是
contentType: "text/xml",
标签: javascript php ajax web-services cordova