2015-09-28 3 views
1

Есть ли способ, которым я могу установить заголовки запросов в титане ?.Как установить заголовки запросов в титане

например: 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(); 

ответ

3

Да попробуйте ниже,

Всегда установлено после открытия запроса

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(); 
+0

Это не работает :( –

+0

@ user3475082 Oppz мой плохой .. проверьте код, который я обновил – jlocker

+0

Ничего себе работает как шарм. Ты спас мой день ... спасибо @jlocker :) –