【问题标题】:How to set request headers in titanium如何在钛中设置请求标头
【发布时间】:2015-09-28 17:13:54
【问题描述】:

有什么方法可以在钛中设置请求标头?

例如: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();

【问题讨论】:

    标签: titanium titanium-alloy


    【解决方案1】:

    是的,试试下面的,

    打开请求后始终设置

    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 我的错..检查我更新的代码
    • 哇就像魅力一样..你拯救了我的一天......谢谢@jlocker :)
    • 太好了...如果我的回答对您有帮助,请接受它作为答案。
    猜你喜欢
    • 1970-01-01
    • 2012-03-28
    • 2018-03-30
    • 2020-10-09
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    相关资源
    最近更新 更多