如何在titanium中设置请求头

如何在titanium中设置请求头,titanium,titanium-alloy,Titanium,Titanium Alloy,有没有办法用钛合金设置请求头 例如:API=ABCDEFGB564321423452343434 我的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("Rece

有没有办法用钛合金设置请求头

例如:API=ABCDEFGB564321423452343434

我的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();

@user3475082 Oppz my bad..检查我更新的代码Wow很有魅力..你救了我一天…谢谢@jlocker:太好了…如果我的答案对你有帮助,请接受它作为答案。