sách gpt4 ăn đã đi

javascript - 使用 json 调用 webService 在 Titanium 中出错,但使用 curl 从终端调用 webService 工作正常

In lại Tác giả: Walker 123 更新时间:2023-11-30 18:32:45 29 4
mua khóa gpt4 giày nike

您好,我正在尝试使用 json 在钛中调用 webService。该 webService 不接受任何参数,所以我只需要调用它。

Đây là mã của tôi:

var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(10000);

xhr.open("POST","http://mytesturl.net/services/json/system.connect");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.send();
xhr.onerror = function() {

Titanium.API.info("some thing is wrong in calling");
};

xhr.onload = function() {

Titanium.API.info("The API response is " + this.responseText);
};

在日志中我得到这个错误:

The API response is {"#error":true,"#data":"Invalid method ","#response_code":405}

我以为 url 是错误的,但是当我尝试从我的终端调用相同的 Web 服务时,即使用 curl 实用程序

curl --data method=system.connect http://mytesturl.net/services/json

我得到了我需要的回应..我在这里做错了什么??

câu trả lời hay nhất

您没有将任何负载传递给服务器,而是尝试将方法作为 URL 的一部分进行传递。您需要将 method=system.connect 添加为 send TRONG dữ liệu 参数函数调用并将 URL 更改为与 curl 请求中的相同 (http://mytesturl.net/services/json)。

关于javascript - 使用 json 调用 webService 在 Titanium 中出错,但使用 curl 从终端调用 webService 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9127372/

29 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress