我想出的解决方案是使用cURL(如@waki所提到的),但是使用了稍作修改的版本来支持SOAP。然后,我对本地PHP文件进行了调用,而不是对第三方API(配置不正确)进行AJAX调用,然后对本地API文件进行了SOAP调用,并将数据传递回我的PHP文件中,然后处理它。这使我忘记了CORS及其相关的所有复杂性。这是代码(从该问题中获取和修改的,但未进行身份验证)。
$post_data = "Some xml here";$soapUrl = "http://yoursite.com/soap.asmx"; // asmx URL of WSDL$headers = array( "Content-type: text/xml;charset="utf-8"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: http://yoursite.com/SOAPAction", "Content-length: " . strlen($post_data),); //SOAPAction: your op URL$url = $soapUrl;// PHP cURL$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // the SOAP requestcurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);$response = curl_exec($ch);if(curl_errno($ch) != 0) { // TODO handle the error}curl_close($ch);// TODO Parse and process the $response variable (returned as XML)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)