titanium - 如何在钛中设置请求 header

标签 titanium titanium-alloy

有什么方法可以在钛中设置请求 header 吗?

例如:API = abcdefgb56432142345234534;

我的xhr:

var url = "http://www.appcelerator.com";
var client = Ti.Network.createHTTPClient({
    // function called when the response data is available
    onload: function(e) {
        Ti.API.info("Received text: " + this.responseText);
        alert('success');
    },
    // function called when an error occurs, including a timeout
    onerror: function(e) {
        Ti.API.debug(e.error);
        alert('error');
    },
    timeout: 5000 // in milliseconds
});
// Prepare the connection.
client.open("GET", url);
// Send the request.
client.send();

最佳答案

是的,请尝试以下方法,

始终在打开请求后设置

var url = "http://www.appcelerator.com";
var client = Ti.Network.createHTTPClient({
    // function called when the response data is available
    onload: function(e) {
        Ti.API.info("Received text: " + this.responseText);
        alert('success');
    },
    // function called when an error occurs, including a timeout
    onerror: function(e) {
        Ti.API.debug(e.error);
        alert('error');
    },
    timeout: 5000 // in milliseconds
});
// Prepare the connection.
client.open("GET", url);

client.setRequestHeader('API','abcdefgb56432142345234534'); //allways set after open
// Send the request.
client.send();

关于titanium - 如何在钛中设置请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32828408/

相关文章:

titanium - Titanium iOS 项目构建失败错误

ios - 钛合金中不调用手势(方向)事件

android - 创建一个按钮数组,只有在单击钛中的上一个按钮时才可见

android - 使用钛合金创建复选框

android - 如何解决 mac 上的错误 : build-manifest. json does not exist in Titanium Studio

ios - 在不使用 Appcelerator Cloudpush (ACS) 的情况下接收从 APNS 到 Titanium (iOS) App 的推送通知?

ios - Titanium Appcelerator ACS - (iPhone) 无法接收成功发送的推送通知

ios - 使用 Titanium 滚动时禁用 TableView 垂直弹跳

javascript - Windows 上的 Appcelerator : No valid Android SDK Targets Found

sqlite - 如何在更新 Web 数据库之前跟踪本地 SQlite 上的数据库更改