有没有办法可以在钛中设置请求标头?。
例如: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();
答案 0 :(得分: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();