interface XMLHttpRequest { attribute EventListener onreadystatechange; readonly attribute unsigned short readyState; void open(in DOMString method, in DOMString url); void open(in DOMString method, in DOMString url, in boolean async); void open(in DOMString method, in DOMString url, in boolean async, in DOMString user); void open(in DOMString method, in DOMString url, in boolean async, in DOMString user, in DOMString password); void setRequestHeader(in DOMString header, in DOMString value); void send(); void send(in DOMString data); void send(in Document data); void abort(); DOMString getAllResponseHeaders(); DOMString getResponseHeader(in DOMString header); readonly attribute DOMString responseText; readonly attribute Document responseXML; readonly attribute unsigned short status; readonly attribute DOMString statusText; };
(1) setRequestHeader() has to be used after request.open(...), where request is a instance of XMLHttpRequest
(2) Setting User-Agent is forbidden by FF as well as some of the other special header fields.
(3) If you're doing things on Android, changing User-Agent through WebView configuration is possible if you're attempting to use WebView to execute some Javascript code and want the request to be sent with a custom User-Agent.
Reference links
http://stackoverflow.com/questions/581383/adding-custom-http-headers-using-javascript
http://stackoverflow.com/questions/2357430/invalid-state-err-dom-exception-11
http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/#xmlhttprequest-members
http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method
沒有留言:
張貼留言