In QML, it seems like I can't call responseURL
from my XMLHttpRequest
object :
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4) {
console.log(xhttp.responseURL)
}
};
For example, using cURL: curl -L -v http://google.com/
I get a 301 Moved Permanently
response then I'm redirected to https://www.google.com/
with status 200 OK
BUT using the XMLHttpRequest
I get an output of qml: undefined
when I would expect it to output the url of wherever I was redirected to. I've also tried using getAllResponseHeaders()
to find the Location:
header, but that isn't usually returned (for security reasons I believe). So, how can I find out to which URL I was redirected?
EDIT: Included is the MRE, which returns no responseURL or location header as it is a 405 error
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
Component.onCompleted: {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4) {
console.log("RESPONSE STATUS: " + xhttp.status)
console.log("RESPONSE HEADERS: " + xhttp.getAllResponseHeaders())
console.log("RESPONSE: " + xhttp.response)
console.log("RESPONSE URL: " + xhttp.responseURL)
}
};
xhttp.open("GET", "https://auth.ebay.com/oauth2/authorize?client_id=TylerMil-Bulba-PRD-81fa8c353-94042920&response_type=code&redirect_uri=Tyler_Miller-TylerMil-Bulba--hfgsw&scope=https://api.ebay.com/oauth/api_scope")
xhttp.send()
}
}
Output:
qml: RESPONSE STATUS: 405
qml: RESPONSE HEADERS: date: Fri, 20 Dec 2019 18:55:18 GMT
content-type: text/html; charset=utf-8
transfer-encoding: chunked
connection: keep-alive
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
rlogid: t6pbhnmpo%3D9iptpbhnmpo*0321%3A4%3E-16f24a9fe8c-0xb06
vary: Accept-Encoding, Accept-Encoding
x-distil-cs: MISS
server: eBayServer
expires: Thu, 01 Jan 1970 00:00:01 GMT
cache-control: private, no-cache, no-store, must-revalidate
edge-control: no-store, bypass-cache
surrogate-control: no-store, bypass-cache
strict-transport-security: max-age=31536000, max-age= 31536000
qml: RESPONSE: <!DOCTYPE html><html lang="en" style="overflow: visible;"><head><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta charset="utf-8"><meta name="google-site-verification" content="RDpd-WPXK6QX0AeQPo4hCtBF-2nKyj3zjzY-H7GgRs8"><meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" href="https://pages.ebay.com/favicon.ico"><title>Security Measure</title>
******removed much of the response body******
</footer></body></html><!-- RcmdId distil_captcha,RlogId t6pujfpmsn5%3F%3Ckuvuwoduovl0*%3B34561-16f24a9fea4-0x2b02 --><!-- SiteId: 0, Environment: production, AppName: splashui, PageId: 2557882 -->
qml: RESPONSE URL: undefined