【发布时间】:2016-02-16 17:32:45
【问题描述】:
我在 Google Cloud 虚拟机上有一个 Web 实例,构建为 UBUNTU
我正在尝试将数据发布到外部 API,但是当我观察流量时,POST 显然变成了 GET。
我检查了服务器 .htaccess 和 site.conf 文件,没有发现任何重写或限制的迹象
我已经尝试过 PHP CURL 和 JQUery。以下是每次尝试的重要代码 sn-ps
curl_setopt($ch, CURLOPT_POST, 1); // I have also tried TRUE
curl_setopt($ch, CURLOPT_POSTFIELDS,"\$xmldata=".urlencode($xmldata));
ob_start();
和Jquery方法(完整)
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="application/javascript">
$(function () {
var example = {
"Title": "REST DN transaction (JSON)",
"Description": "REST DN transaction (JSON)",
"TransactionType": 0,
"Partner": {
"PartnerId": xxxx },
"Buyer": {
"Email": "xxxx@hotmail.com", "Initiator": false,
"CompanyChk": false,
"AutoAgree": false, "AgreementChecked": false
}, "Seller": {
"Email": "xxxx@hotmail.com", "Initiator": true,
"CompanyChk": false,
"AutoAgree": false, "AgreementChecked": false
}, "LineItems": [
{
"ItemName": "test.com", "Description": "DN description", "Quantity": 1,
"Price": 2000,
"Accept": true,
"SellComm": 9.1,
"BuyComm": 10.1,
}],
"EPayment": 0,
"ShipmentFee": 0,
"ShipmentPayment":0,
"DomainNameType": 0,
"InspectionLength": 6,
"Currency": "USD",
"Fulfillment": 2,
"CommissionType": 1,
"InitiationDate": "2014-04-15",
"TermsLocked": true,
"AllowReject": true
};
$.post({
type: "POST",
method: "POST",
dataType: 'jsonp',
data :JSON.stringify(example),
url: "https://thedomain.com/api/Transaction",
contentType: "application/json"
});
});
</script>
我也试过 $.ajax(
域名是占位符
谁能告诉我为什么在谷歌开发者控制台中,当我观看时间线时,传出请求总是一个 GET
API 还返回一条消息,指示 GET 是不允许的
【问题讨论】:
-
澄清一下,发送的数据没有错误,我只是在这两种情况下都没有将它添加到sn-p
-
如果您不向我们展示更多代码,我们将无法告诉您错误是什么...... curl 不只是为了自娱自乐地将 POST 切换为 GET!
-
你说得对!!但它是!!我将添加其余代码
-
我已经完整地添加了 JQuery 版本.. 什么都没有,我运行这个脚本并观察控制台,它在每个阶段都显示为 GET..,任何时候都不是 POST 方法.. 除非我读错了谷歌开发控制台