<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110051/https-post-request-to-azure-endpoint</link><description>Hi, 
 I&amp;#39;m trying to make a https post request to my Azure endpoint with a nrf9160 using Zephyr. I&amp;#39;ve first made the post request in a python script to check if everything is working on the Azure side, and that seems to work fine, I&amp;#39;ve included the python</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Apr 2024 14:36:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110051/https-post-request-to-azure-endpoint" /><item><title>RE: HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/thread/479275?ContentTypeID=1</link><pubDate>Wed, 17 Apr 2024 14:36:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a63d388a-096a-4516-a0e7-ced3c23cff76</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;You cannot use a socket that has been closed. You will need to open a new socket.&lt;/p&gt;
&lt;p&gt;Though it is also possible to change the receive logic to not have to close the connection in the first place. One such example would be the download_client library, which uses a series of content-range requests to download large files. To see how it is done, you can look at the code in nrf\subsys\net\lib\download_client\src\download_client.c. In NCS v2.6.0, the download loop itself is on line 830-885.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/thread/479159?ContentTypeID=1</link><pubDate>Wed, 17 Apr 2024 09:23:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86e23e3e-fad1-465d-8822-5ed5c14d9fb2</guid><dc:creator>NilsDR</dc:creator><description>&lt;p&gt;Or even better, how do I open the connection again after it is closed? I get error 128 when I try to connect again using the same fd:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;printk(&amp;quot;Connecting to %s:%d\n&amp;quot;, HTTPS_HOSTNAME, ntohs(((struct sockaddr_in *)(res-&amp;gt;ai_addr))-&amp;gt;sin_port));
err = connect(fd, res-&amp;gt;ai_addr, res-&amp;gt;ai_addrlen);
if (err) {
	printk(&amp;quot;connect() failed, err: %d\n&amp;quot;, errno);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/thread/479015?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2024 13:41:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbeade1c-1af1-4a43-8799-f190b799bc28</guid><dc:creator>NilsDR</dc:creator><description>&lt;p&gt;Thanks, you were right it was the certificate that was wrong. I can now make a post request to both hostnames, however, the sample uses the &amp;quot;connection: close&amp;quot; which closes the connection after 1 post request. Is there a way to not close the connection after sending a request? I&amp;#39;ve tried &amp;quot;keep-alive&amp;quot; but the sample relies on closing the connection when receiving data, so you have to receive data in another way?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;off = 0;
do {
	bytes = recv(fd, &amp;amp;recv_buf[off], 2100 - off, 0);
	if (bytes &amp;lt; 0) {
		printk(&amp;quot;recv() failed, err %d\n&amp;quot;, errno);
		k_sleep(K_MSEC(1000));
	}
	off += bytes;
} while (bytes != 0 /* peer closed connection */);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/thread/478787?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 13:09:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5f00ff7-3c24-4a19-86ed-3c700d458cda</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;You need to print the value of errno to see the actual error code from connect.&lt;/p&gt;
&lt;p&gt;My guess is that you have something wrong with the certificates.&lt;/p&gt;
&lt;p&gt;Also, when debugging these kinds lf issues, a modem trace can be very useful. With the Cellular Monitor application in nRF Connect for Dekstop, you can decode the trace so that you can see that packets sent on air in Wireshark. This will e.g. let you see where in the TLS handshake the problem occurs.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/nrf-connect-cellularmonitor/page/requirements.html"&gt;https://docs.nordicsemi.com/bundle/nrf-connect-cellularmonitor/page/requirements.html&lt;/a&gt; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/thread/478754?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 11:53:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88a7a932-9430-4308-8543-13b0e759777e</guid><dc:creator>NilsDR</dc:creator><description>&lt;p&gt;Thank you, that seems to work. I can now connect to&amp;nbsp;login.microsoftonline.com and make a post request to get a bearer token, however, when I try to connect to the next hostname: log-ingestion-xxxx.westeurope-1.ingest.monitor.azure.com, i get a new error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.3.99-ncs1 ***
HTTPS client sample started
Certificate match
Waiting for network.. PDP context 0 activated
PDP context 0 error, PDN type IPv4 only allowed
OK
Looking up log-ingestion-xxxx.westeurope-1.ingest.monitor.azure.com
Resolved 51.xxx.xx.xxx (AF_INET)
Connecting to log-ingestion-xxxx.westeurope-1.ingest.monitor.azure.com:443
connect() failed, err: -1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The connection works perfectly with the other hostname, so why does it fail here? And what does error code -1 mean?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HTTPS post request to Azure endpoint</title><link>https://devzone.nordicsemi.com/thread/477754?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2024 10:01:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df0bb614-9a6e-4ceb-a6fc-1c0e64b1b754</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;When calling getaddrinfo, try to use just the hostname, not the full URL.&lt;/p&gt;
&lt;p&gt;I.e. do the DNS lookup on just &amp;quot;login.microsoftonline.com&amp;quot;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>