我在第三方API上调用POST,我一直在使用jQuery的$ .ajax函数.但是,当我拨打电话时,我收到以下错误:XMLHttpRequest cannot load http://the-url.com. The request was redirected to 'http://the-url.com/anotherlocation', which is disallowed for cross-origin requests that require preflight.
我在这篇文章中看到这可能是一个Webkit错误,所以我在Firefox中尝试过它(我在Chrome中开发)并得到了相同的结果.我在Chrome和Firefox上尝试了这个,我得到了相同的结果.
根据这篇文章,我也尝试使用jsonp crossDomain将$ .ajax函数的属性true设置为并设置dataType为jsonp.但是,这导致500内部服务器错误.
当我使用--disable-web-security标志启动Chrome时,我没有任何问题.但是,如果我正常启动浏览器,那么我会收到错误.
所以,我想这可能是一个由两部分组成的问题.我该怎么做才能提出这个跨域请求?如果答案是JSONP,那么我该如何确定第三方API是否设置正确以支持这一点?
编辑:这是我在禁用浏览器安全性的情况下拨打电话的屏幕截图:https://drive.google.com/file/d/0Bzo7loNBQcmjUjk5YWNWLXM2SVE/edit?usp =sharing
这是我在启用浏览器安全性的情况下拨打电话时的屏幕截图(正常情况下):https://drive.google.com/file/d/0Bzo7loNBQcmjam5NQ3BKWUluRE0/edit?usp=sharing
我很困惑
Soap curl request我在这里找到了一个带有CURL的PHP示例
SOAP请求
和使用SoapClientPHP的
Soap请求http://php.net/manual/en/class.soapclient.php
我的疑问和怀疑是第一 - 这些都填补了同样的目的.
第二 - 如果它们用于相同目的,是否存在任何性能差异.
提前致谢
我需要将内容类型从“text/xml;charset=utf-8”更改为“application/soap+xml;charset=utf-8”。
我正在使用 PHP 中默认存在的 SoapClient 类将请求从 PHP 发送到另一台服务器(Oracle 服务器)。我正在使用 PHP v7.0.10。
根据 SoapClient 文档,我应该将 options 数组中的 soap_version 设置为 SOAP_1_2,它会更改内容类型,但它不会这样做。
SOAP 请求
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
<soap:Header/>
<soap:Body>
<pub:runReport>
<pub:reportRequest>
<pub:reportAbsolutePath>/Human Capital Management/Workforce Management/Human Resources Dashboard/Fusion User Information.xdo</pub:reportAbsolutePath>
<pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
</pub:reportRequest>
</pub:runReport>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
PHP代码
$WSDL = "https://example.com/xmlpserver/services/ExternalReportWSSService?WSDL";
$soap_options = array(
'uri' => 'http://www.w3.org/2003/05/soap-envelope',
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'connection_timeout' => 30,
'trace' => true,
'encoding' => 'UTF-8',
// 'exceptions' => true,
'location' => $WSDL,
'login' …Run Code Online (Sandbox Code Playgroud) 我有一个简单的PHP脚本,通过cURL发送HTTP POST请求,并期望响应中的json字符串(本来喜欢使用像pecl_http/HTTPRequest这样的现有库,但不能).调用始终失败,出现415错误 - 不支持的媒体类型.我想我没有正确配置cURL,但经过多次搜索,我无法找出我做错了什么.这是一些代码:
class URLRequest
{
public $url;
public $headers;
public $params;
public $body;
public $expectedFormat;
public $method;
public function URLRequest($aUrl, array $aHeaders, array $aParams, $aFormat = "json", $isPost = false, $aBody = "+")
{
$this->url = $aUrl;
$this->headers = $aHeaders;
$this->params = $aParams;
$this->expectedFormat = $aFormat;
$this->method = ($isPost ? "POST" : "GET");
$this->body = $aBody;
}
public function exec()
{
$queryStr = "?";
foreach($this->params as $key=>$val)
$queryStr .= $key . "=" . $val . "&";
//trim the …Run Code Online (Sandbox Code Playgroud)