Note that there are some explanatory texts on larger screens.

plurals
  1. POXMLHTTPRequest response doesnt contain Location field in the header
    primarykey
    data
    text
    <p>I was trying to modify the adblockplus code for testing purpose. I was modifying the code to send a http get request on a URL and get the final URL from the response. I tried using the below code, but the response doesn't contain the Location field in the header response. I am doing this within a firefox-extension, so I dont think cross-domain request would be any issue. Why is it that I am not able to fetch the Location field from the response? Is there a better way to accomplish this task ?</p> <p>Input URL- <a href="http://netspiderads3.indiatimes.com/ads.dll/clickthrough?msid=17796167&amp;cid=3224&amp;slotid=1203&amp;nsRndNo=817685688" rel="nofollow">http://netspiderads3.indiatimes.com/ads.dll/clickthrough?msid=17796167&amp;cid=3224&amp;slotid=1203&amp;nsRndNo=817685688</a></p> <p>Expected output-<a href="http://www.mensxp.com/" rel="nofollow">http://www.mensxp.com/</a></p> <p>Actual Output- Location: null</p> <p>Here is the code I am using-</p> <pre><code>function geturl(url){ let req= Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); req.open("GET", url); req.overrideMimeType("text/plain"); req.send(null); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200) { try { location = req.getResponseHeader("Location"); console.log("Location is: " + location); } catch(e){ console.log("Error reading the response: " + e.toString()); } } } </code></pre> <p><strong>Solution</strong>-</p> <p>I finally found the solution for this. I was not getting the final response. So I set the redirection limit to 0, now I can get the Location field in the header. Here is what I added to my code-</p> <pre><code>if (request.channel instanceof Ci.nsIHttpChannel) request.channel.redirectionLimit = 0; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload