<?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>Sending file over HTTP - Bad Request</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96869/sending-file-over-http---bad-request</link><description>Hi, 
 
 
 I&amp;#39;m trying to send files over HTTP, using the nRF9160. In order to do this, I&amp;#39;m using the https_client sample. It was working with the initial configuration (HEAD request, to example.com). Now I just changed the host, and request, and I get</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Feb 2023 14:26:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96869/sending-file-over-http---bad-request" /><item><title>RE: Sending file over HTTP - Bad Request</title><link>https://devzone.nordicsemi.com/thread/411410?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 14:26:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d407f713-353a-4cd6-b94b-7471d782c86e</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Glad to hear that you found a solution!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending file over HTTP - Bad Request</title><link>https://devzone.nordicsemi.com/thread/411292?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 09:41:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fea19b6-d978-48e4-896d-91bc06841d27</guid><dc:creator>A. Mullot</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I found what the problem was. I didn&amp;#39;t have to call the socket as non-blocking with fcntl(). Actually, for my application, the server answer always is below 2048 bytes (the size of the recv_buf). So I only have to call recv() once, and the whole answer will fit in the reception buffer. The only thing I could do otherwise would be to call recv() while there isn&amp;#39;t &amp;quot;\r\n\r\n&amp;quot; in the answer.&lt;br /&gt;&lt;br /&gt;Thank you for the help !&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Armand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending file over HTTP - Bad Request</title><link>https://devzone.nordicsemi.com/thread/411170?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 15:44:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffe3eb7c-0c44-458a-81bd-5b21c69ca8d7</guid><dc:creator>A. Mullot</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for your answer.&lt;/p&gt;
&lt;p&gt;I realized I did have a content-length issue, however this seems solved. I am now meeting another problem : the&amp;nbsp;recv() function (&lt;a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html"&gt;official doc&lt;/a&gt;) never returns... Here is the part of the code from the https_client sample (&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/nrf9160/https_client/README.html"&gt;https_client sample&lt;/a&gt;) that causes trouble :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;off = 0;
	do {
		printk(&amp;quot;Before recv()\n&amp;quot;);
		bytes = recv(fd, &amp;amp;recv_buf[off], RECV_BUF_SIZE - off, 0);
		printk(&amp;quot;After recv()\n&amp;quot;);
		if (bytes &amp;lt; 0) {
			LOG_ERR(&amp;quot;recv() failed, err %d&amp;quot;, errno);
			clean_up();
		}
		off += bytes;
	} while (bytes != 0 /* peer closed connection */);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The output is the following :&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1676993952764v2.png" /&gt;&lt;/p&gt;
&lt;p&gt;The recv() function is called one first time, and runs just fine. It returns 148 at the first iteration. It is in the second iteration that it keeps the whole program from moving on.&lt;/p&gt;
&lt;p&gt;I suspect that this is caused by the \r\n\r\n that you mentionned before. Maybe the end of the request is not clearly identified by the server ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anyway, I&amp;#39;ll keep on investigating this, and thanks for your suggestions.&lt;br /&gt;&lt;br /&gt;By the way, I had already updated the CA to fit my server.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT : I realized that the code gets stuck in recv() because it is called as blocking. I&amp;#39;m trying to change this, using&amp;nbsp;fcntl(fd, F_SETFL, O_NONBLOCK); but without great success so far. I&amp;#39;ll let you know.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Armand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending file over HTTP - Bad Request</title><link>https://devzone.nordicsemi.com/thread/411137?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 14:09:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:acae1126-012d-4d63-98fc-976bc0c163d5</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to upload a file, you need to construct your POST correctly.&lt;/p&gt;
&lt;p&gt;&amp;quot;\r\n\r\n&amp;quot; is effectively end of the header, so your current POST&amp;nbsp;might&amp;nbsp;not behave as you intend it to. You should also dynamically align the Content-Length according to your http body length.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/50447483/end-of-http-header"&gt;https://stackoverflow.com/questions/50447483/end-of-http-header&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A side-note, if you are using HTTPS, be sure to change your CA root according to the domain that you&amp;#39;re connecting to. You can see the chain by using openssl, similar to what is done here:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/78816/changing-certificate-in-https_client-sample/326383"&gt;RE: changing certificate in https_client sample&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>