<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HTTPS requests with XMLHttpRequest [Resolved]]]></title><description><![CDATA[<p dir="auto">Hi everyone,</p>
<p dir="auto">I have an issue sending HTTPS requests using XMLHttpRequest().<br />
My code works well with non secure connections but I always have an error when sending the request to secure server.</p>
<p dir="auto">Here is the code I'm using to send a simple JSON request.</p>
<pre><code>  function callRequest(url) {
    var req = new XMLHttpRequest();

    req.open("get", url, true);
    req.setRequestHeader("Content-type", "application/json");
    if (settings.myAuth != "") {
      req.setRequestHeader("Authorization", "Basic "+settings.myAuth)
    }
    req.onreadystatechange = function() {requestItem.onChange(req)}
    req.send();
  } // callRequest()
</code></pre>
<p dir="auto">Is there something I miss in my usage of XMLHttpRequest() or is there another way to address secured API?<br />
I'm trying to improve my app for domoticz and I first thought it was because of self generated certificate, but then I started another app (a client for Slack messenger) and I had the same issue with HTTPS requests.</p>
<p dir="auto">I'm beginner in QML and Javascript, but I'm advanced developer in QT/C++.<br />
So maybe my question is one of a noob, but I can't figure it out by myself.</p>
<p dir="auto">Another idea I had was maybe it requires  different rights for the app?<br />
I only set "networking" and I added "push-notification-client" for experimenting a bit.</p>
<p dir="auto">Regards,<br />
Richard</p>
]]></description><link>https://forums.ubports.com/topic/2686/https-requests-with-xmlhttprequest-resolved</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 08:30:26 GMT</lastBuildDate><atom:link href="https://forums.ubports.com/topic/2686.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 May 2019 19:49:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Mon, 24 Jun 2019 14:19:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wangqinfeng" aria-label="Profile: wangqinfeng">@<bdi>wangqinfeng</bdi></a> hi, welcome and remember that this Forum is English only <img src="https://forums.ubports.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=60240fe800f" class="not-responsive emoji emoji-android emoji--wink" style="height:23px;width:auto;vertical-align:middle" title=";)" alt="😉" /></p>
<p dir="auto">It seems you're saying something like <em>Thank you! Solved my problem!</em> and that's why I didn't remove your post but, please, keep in mind that English requirement <img src="https://forums.ubports.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=60240fe800f" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://forums.ubports.com/post/20729</link><guid isPermaLink="true">https://forums.ubports.com/post/20729</guid><dc:creator><![CDATA[advocatux]]></dc:creator><pubDate>Mon, 24 Jun 2019 14:19:17 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Mon, 24 Jun 2019 13:25:51 GMT]]></title><description><![CDATA[<p dir="auto">谢谢您！解决了我的问题！<img src="https://forums.ubports.com/assets/plugins/nodebb-plugin-emoji/emoji/android/263a.png?v=60240fe800f" class="not-responsive emoji emoji-android emoji--relaxed" style="height:23px;width:auto;vertical-align:middle" title=":relaxed:" alt="☺" /></p>
]]></description><link>https://forums.ubports.com/post/20728</link><guid isPermaLink="true">https://forums.ubports.com/post/20728</guid><dc:creator><![CDATA[wangqinfeng]]></dc:creator><pubDate>Mon, 24 Jun 2019 13:25:51 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Mon, 10 Jun 2019 17:16:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/applee" aria-label="Profile: AppLee">@<bdi>AppLee</bdi></a> said in <a href="/post/20567">HTTPS requests with XMLHttpRequest [Resolved]</a>:</p>
<blockquote>
<p dir="auto">When you change apparmor or the app logo, you have to uninstall the app before pushing it again to debug, changes have no effect otherwise...</p>
</blockquote>
<p dir="auto">There is a known issue, where you need to change the version number whenever you change the apparmor, to cause the profile to be regenerated.</p>
]]></description><link>https://forums.ubports.com/post/20569</link><guid isPermaLink="true">https://forums.ubports.com/post/20569</guid><dc:creator><![CDATA[dobey]]></dc:creator><pubDate>Mon, 10 Jun 2019 17:16:17 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Mon, 10 Jun 2019 15:34:52 GMT]]></title><description><![CDATA[<p dir="auto">Ok guys, I finally found my mistake, so here is the story.<br />
After too much time spent on this issue, I decided to use the "big gun" to move forward.</p>
<p dir="auto">So, this weekend I started to create a C++ plugin based on QNetworkAccessManager.<br />
And I did the same error, so I got nothing in return.<br />
Few coding later (after implementing the error management) I had my answer : Host not found !?!</p>
<p dir="auto">I tried with another HTTPS URI and I got an access denied error...</p>
<p dir="auto">After a few try I finally understood how stupid I had been.<br />
I forgot to add "networking" in the app apparmor !!!</p>
<p dir="auto">In fact my many tries and switching from a working app to a WIP app hid the real problem.</p>
<p dir="auto">But it seems there is a little tricky thing:<br />
When you change apparmor or the app logo, you have to uninstall the app before pushing it again to debug, changes have no effect otherwise...</p>
<p dir="auto">Many thanks for all the help guys. I'll be more cautious next time</p>
]]></description><link>https://forums.ubports.com/post/20567</link><guid isPermaLink="true">https://forums.ubports.com/post/20567</guid><dc:creator><![CDATA[AppLee]]></dc:creator><pubDate>Mon, 10 Jun 2019 15:34:52 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Thu, 16 May 2019 18:16:31 GMT]]></title><description><![CDATA[<p dir="auto">Hi, I promised a feedback.</p>
<p dir="auto">My first tests weren't successful, I need to work on how to implement the <code>onerror</code> method to have better understanding of my issue.</p>
<p dir="auto">Thanks again for your ideas</p>
]]></description><link>https://forums.ubports.com/post/20026</link><guid isPermaLink="true">https://forums.ubports.com/post/20026</guid><dc:creator><![CDATA[AppLee]]></dc:creator><pubDate>Thu, 16 May 2019 18:16:31 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Fri, 10 May 2019 17:08:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dobey" aria-label="Profile: dobey">@<bdi>dobey</bdi></a>  and <a class="plugin-mentions-user plugin-mentions-a" href="/user/ingo" aria-label="Profile: Ingo">@<bdi>Ingo</bdi></a></p>
<p dir="auto">Thank you both, I'm looking into the code <a class="plugin-mentions-user plugin-mentions-a" href="/user/dobey" aria-label="Profile: dobey">@<bdi>dobey</bdi></a> posted to implement the <code>onerror</code> so I can go forward.<br />
I'll give you an update tomorrow after spending some time on this.</p>
]]></description><link>https://forums.ubports.com/post/19788</link><guid isPermaLink="true">https://forums.ubports.com/post/19788</guid><dc:creator><![CDATA[AppLee]]></dc:creator><pubDate>Fri, 10 May 2019 17:08:14 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Fri, 10 May 2019 17:02:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/applee" aria-label="Profile: AppLee">@<bdi>AppLee</bdi></a> said in <a href="/post/19781">HTTPS requests with XMLHttpRequest</a>:</p>
<blockquote>
<p dir="auto">In each case I got the same answer: status=0 and readyState=DONE<br />
There no other kind of error message, I don't know what you expect.</p>
</blockquote>
<p dir="auto">This generally means that what happened was a connection to the server was not possible. So you of course will not get the response status code from the server, and instead you need to handle the <code>onerror</code> callback for the <code>XMLHttpRequest</code> object, to get an error. Most common cause there is connecting to a site with cert that couldn't be verified.</p>
]]></description><link>https://forums.ubports.com/post/19787</link><guid isPermaLink="true">https://forums.ubports.com/post/19787</guid><dc:creator><![CDATA[dobey]]></dc:creator><pubDate>Fri, 10 May 2019 17:02:54 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Fri, 10 May 2019 16:27:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/applee" aria-label="Profile: AppLee">@<bdi>AppLee</bdi></a> said in <a href="/post/19781">HTTPS requests with XMLHttpRequest</a>:</p>
<blockquote>
<p dir="auto">There no other kind of error message, I don't know what you expect.</p>
</blockquote>
<p dir="auto">For that I guess you need to add an <code>xhr.onerror</code> callback (or whatever is needed to catch errors of XMLHttpRequest in JavaScript).</p>
]]></description><link>https://forums.ubports.com/post/19782</link><guid isPermaLink="true">https://forums.ubports.com/post/19782</guid><dc:creator><![CDATA[Ingo]]></dc:creator><pubDate>Fri, 10 May 2019 16:27:06 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Fri, 10 May 2019 16:22:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dobey" aria-label="Profile: dobey">@<bdi>dobey</bdi></a> I don't know how a specific url will change anything, because it does not work with any https...<br />
The first test I did was for this app :<br />
<a href="https://gitlab.com/AppsLee/domoticz-ubports" rel="nofollow ugc">https://gitlab.com/AppsLee/domoticz-ubports</a></p>
<p dir="auto">In this case, the certificate is <strong>not ok</strong>, so I didn't worry much.<br />
Now I'm creating a client for Slack, so I tried with a genuine HTTPS request (I use the same <code>Request.qml</code> as for domoticz, but now I put some debug code)<br />
The url tested is : <a href="https://slack.com/api/conversations.history?token=" rel="nofollow ugc">https://slack.com/api/conversations.history?token=</a>&lt;myToken&gt;&amp;channel=&lt;myChannelId&gt;<br />
I also tested other HTTPS url : <a href="https://www.appliancetherapy.com" rel="nofollow ugc">https://www.appliancetherapy.com</a> and <a href="https://addons.mozilla.org" rel="nofollow ugc">https://addons.mozilla.org</a> for example, but none worked, but all of them worked with <em>Morph browser</em>.</p>
<p dir="auto">In each case I got the same answer: <code>status=0</code> and <code>readyState=DONE</code><br />
There no other kind of error message, I don't know what you expect.</p>
<p dir="auto">To trigger the request I use this:</p>
<pre><code>Component.onCompleted: reqFct.getMessages("https://addons.mozilla.org")
</code></pre>
<p dir="auto">The request is sent by:</p>
<pre><code>function getMessages(url) {
  var req = new XMLHttpRequest();
  req.open("get", url, true);
  req.onreadystatechange = function() {requestItem.readMessages(req)}
  req.send();
} // getMessages()
</code></pre>
<p dir="auto">And the readMessages has been reduced to that:</p>
<pre><code>function readMessages(objReq, refresh) {
  if ( objReq.readyState === XMLHttpRequest.DONE ) {
    if (objReq.status == 200) {
      inputMsg.text += "Answer OK\n"
    } else {
      inputMsg.text += "Answer KO "+objReq.status+"\n"
    }
    inputMsg.text += "YY"+objReq.responseText+"XX\n"
    }
  } else {
    inputMsg.text += "NOT DONE yet\n"
  }
} // readMessages()
</code></pre>
<p dir="auto">In inputMsg, I've got:</p>
<pre><code>Answer KO 0
YYXX
</code></pre>
<p dir="auto">I removed the <code>Content-type</code> just to be sure (I added it hoping it might help) but same result.<br />
I tried various example from the net but nothing solved my issue, that's why I thought maybe I need to enable something or send some magic command to enable HTTPS.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ingo" aria-label="Profile: Ingo">@<bdi>Ingo</bdi></a>  thanks for the links, I'll read, try and go back here later this weekend.</p>
]]></description><link>https://forums.ubports.com/post/19781</link><guid isPermaLink="true">https://forums.ubports.com/post/19781</guid><dc:creator><![CDATA[AppLee]]></dc:creator><pubDate>Fri, 10 May 2019 16:22:12 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Fri, 10 May 2019 07:11:20 GMT]]></title><description><![CDATA[<p dir="auto">Maybe this code helps debugging the problem with HTTPS?<br />
<a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/How_to_check_the_secruity_state_of_an_XMLHTTPRequest_over_SSL" rel="nofollow ugc">https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/How_to_check_the_secruity_state_of_an_XMLHTTPRequest_over_SSL</a></p>
<p dir="auto">readyState=4 while status is still 0 sounds a bit as if the request never was actually made to the server, e.g. something in the handshake went wrong.<br />
Maybe this points in the right direction: <a href="https://stackoverflow.com/questions/36416389/why-does-my-xmlhttprequest-have-readystate-4-but-status-0" rel="nofollow ugc">https://stackoverflow.com/questions/36416389/why-does-my-xmlhttprequest-have-readystate-4-but-status-0</a></p>
]]></description><link>https://forums.ubports.com/post/19734</link><guid isPermaLink="true">https://forums.ubports.com/post/19734</guid><dc:creator><![CDATA[Ingo]]></dc:creator><pubDate>Fri, 10 May 2019 07:11:20 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Fri, 10 May 2019 01:38:45 GMT]]></title><description><![CDATA[<p dir="auto">Can you please specify the exact error you are receiving, and what URL you are trying to access?</p>
<p dir="auto">As it stands, everyone has to guess at what you're getting, which makes it quite difficult to provide help. Is the code in question on github/gitlab/etc… somewhere? If others can run the code themselves, it will be easier to provide solutions.</p>
<p dir="auto">There is nothing special needed to open HTTPS URLs via XMLHttpRequest. As long as the certificate and request are valid, it will work.</p>
<p dir="auto">BTW, setting <code>Content-Type</code> header on a <code>GET</code> request, is not correct. Also, the way you're setting the <code>Authorization</code> header does not work for either OAuth 1.0 or 2.0.</p>
]]></description><link>https://forums.ubports.com/post/19728</link><guid isPermaLink="true">https://forums.ubports.com/post/19728</guid><dc:creator><![CDATA[dobey]]></dc:creator><pubDate>Fri, 10 May 2019 01:38:45 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Thu, 09 May 2019 20:38:45 GMT]]></title><description><![CDATA[<p dir="auto">My issue is with any https url. I tried with different kind of URL to identify the source of my problem.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ingo" aria-label="Profile: Ingo">@<bdi>Ingo</bdi></a> I checked the values for <em><strong>req.readyState</strong></em> and <em><strong>req.status</strong></em>, req.readyState=4 as expected and req.status=0 wich is bad news ; I expect 200</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/haveaniceday" aria-label="Profile: haveaniceday">@<bdi>haveaniceday</bdi></a> Yes, I tested the url from Slack's API in the web browser and I got my JSON answer as expected.<br />
With domoticz https url I've got an error because the certificate is self validated.<br />
That is not my issue.<br />
So the problem is not between my device and the URL.</p>
<p dir="auto">With HTTP request : everything goes well, so my code seems fine except if something special has to be done for HTTPS requests ; hence my question here...</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/krille" aria-label="Profile: Krille">@<bdi>Krille</bdi></a> The authentication was not required when I tried HTTPS requests (start small, grow big <img src="https://forums.ubports.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=60240fe800f" class="not-responsive emoji emoji-android emoji--wink" style="height:23px;width:auto;vertical-align:middle" title=";)" alt="😉" /> )</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/flohack" aria-label="Profile: Flohack">@<bdi>Flohack</bdi></a> Yes, I suspected something like that too, but I don't know how to check or fix anything on this side.</p>
<p dir="auto">Maybe I have to try another method to send my requests ; I mainly send them to request JSON</p>
<p dir="auto">I'm noob developing for UT, I don't know if I can debug the code executed on my phone ; I use popups and text items to give me hints <img src="https://forums.ubports.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61b.png?v=60240fe800f" class="not-responsive emoji emoji-android emoji--stuck_out_tongue" style="height:23px;width:auto;vertical-align:middle" title=":p" alt="😛" /></p>
<p dir="auto">Thanks for your answers, I hope to find and answer and that it could help new developers too!</p>
]]></description><link>https://forums.ubports.com/post/19725</link><guid isPermaLink="true">https://forums.ubports.com/post/19725</guid><dc:creator><![CDATA[AppLee]]></dc:creator><pubDate>Thu, 09 May 2019 20:38:45 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Thu, 09 May 2019 19:39:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/krille" aria-label="Profile: Krille">@<bdi>Krille</bdi></a> he said it works unsecured, so I assume the problem is with https, certificate exchange etc but not with authorization.</p>
]]></description><link>https://forums.ubports.com/post/19724</link><guid isPermaLink="true">https://forums.ubports.com/post/19724</guid><dc:creator><![CDATA[flohack]]></dc:creator><pubDate>Thu, 09 May 2019 19:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Thu, 09 May 2019 07:11:04 GMT]]></title><description><![CDATA[<p dir="auto">Do you have the exact error message?</p>
]]></description><link>https://forums.ubports.com/post/19712</link><guid isPermaLink="true">https://forums.ubports.com/post/19712</guid><dc:creator><![CDATA[Ingo]]></dc:creator><pubDate>Thu, 09 May 2019 07:11:04 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Thu, 09 May 2019 05:40:27 GMT]]></title><description><![CDATA[<p dir="auto">I don't see any problems with your request. So the problem is this line?</p>
<pre><code>req.setRequestHeader("Authorization", "Basic "+settings.myAuth)
</code></pre>
<p dir="auto">Are you sure that it is 'Basic' and not the keyword 'Bearer'?</p>
]]></description><link>https://forums.ubports.com/post/19711</link><guid isPermaLink="true">https://forums.ubports.com/post/19711</guid><dc:creator><![CDATA[Krille]]></dc:creator><pubDate>Thu, 09 May 2019 05:40:27 GMT</pubDate></item><item><title><![CDATA[Reply to HTTPS requests with XMLHttpRequest [Resolved] on Wed, 08 May 2019 22:30:24 GMT]]></title><description><![CDATA[<p dir="auto">What happens if you enter the url with HTTPS in the address bar of the web browser? Does it work or are there certificate errors?</p>
]]></description><link>https://forums.ubports.com/post/19709</link><guid isPermaLink="true">https://forums.ubports.com/post/19709</guid><dc:creator><![CDATA[haveaniceday]]></dc:creator><pubDate>Wed, 08 May 2019 22:30:24 GMT</pubDate></item></channel></rss>