<?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>How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46094/how-to-make-http-post-no-libcurl</link><description>Hi, all! 
 Have nRF9160. 
 I&amp;#39;m using http sample as template to make http requests get/post. I send it without any lib to build requests. I can&amp;#39;t attach libcurl to nRF9160, and as I understand it is now impossible to using libcurl on nRF9160. 
 Maybe</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 02 Dec 2023 17:48:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46094/how-to-make-http-post-no-libcurl" /><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/458612?ContentTypeID=1</link><pubDate>Sat, 02 Dec 2023 17:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf3476bc-0d1b-4b78-b69a-67f2ba5844a3</guid><dc:creator>Piter</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/hng"&gt;Hoang&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tried to use your http post code implementation but some errors occurred!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/0285.s.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211430?ContentTypeID=1</link><pubDate>Tue, 24 Sep 2019 07:06:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee25d6dc-777b-44dc-b238-245cde06b5be</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/dennisng"&gt;DennisNG&lt;/a&gt;, please create a new thread for the debugging issue and try to include relevant information about your setup. E.g., what jlink programmer you use, debug log, etc.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211381?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 19:08:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ca849e0-6fd3-4a25-bb51-7f712937de87</guid><dc:creator>DennisNG</dc:creator><description>&lt;p&gt;Thanks Hoang!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;appreciate the help!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;br&lt;/p&gt;
&lt;p&gt;Dennis&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211379?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 18:57:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fa432d1-0945-4d77-b017-d3b42564bd01</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;hi &lt;a href="https://devzone.nordicsemi.com/members/dennisng"&gt;DennisNG&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[quote userid="83332" url="~//nordic-q-a/46094/how-to-make-http-post-no-libcurl/211378"][/quote]&lt;/p&gt;
&lt;p&gt;Your code works on Thingy:91 !.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m able to flash this in and I could see that its updating ur server! [Sorry for using it]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thats ok, I saw it. No problem for me.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;About J-link Debugger problem, &lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt; will help you, I dont use it, so I dont know &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Good luck&lt;/p&gt;
&lt;p&gt;Hoang Nguyen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211378?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 18:39:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a92b2cd-9da5-428d-bdb1-e7b31feed19d</guid><dc:creator>DennisNG</dc:creator><description>&lt;p&gt;Hi Hoang,&lt;/p&gt;
&lt;p&gt;Your code works on Thingy:91 !.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m able to flash this in and I could see that its updating ur server! [Sorry for using it]&lt;/p&gt;
&lt;p&gt;However, I&amp;#39;m having some issues trying to attach my J-link Debugger. It&amp;#39;s always giving me a fault when I attach and run. I&amp;#39;m setting a break point in main but it never gets there.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m very new with Zephyr.. thanks for bearing with me.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;br&lt;/p&gt;
&lt;p&gt;Dennis&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211122?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 07:50:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea1c7fe7-b6a5-475e-9527-6211e22ef752</guid><dc:creator>DennisNG</dc:creator><description>&lt;p&gt;Thanks Hoang! I&amp;#39;ll give it a shot.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211121?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 07:49:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20329ea6-e052-4446-aa52-78ef0869cb9a</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;hi &lt;a href="https://devzone.nordicsemi.com/members/dennisng"&gt;DennisNG&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is the one http post, I m using to run on the THINGY:91&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/thingy_5F00_91_5F00_http_5F00_23sept.zip"&gt;devzone.nordicsemi.com/.../thingy_5F00_91_5F00_http_5F00_23sept.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;run with ncs_master branch.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope it can help&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hoang Nguyen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211110?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 07:30:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2fde68d-2f86-48d8-b77b-4073198f5642</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;hi &lt;a href="https://devzone.nordicsemi.com/members/dennisng"&gt;DennisNG&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You want http post,is it right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211109?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 07:29:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8edb59a7-0b56-4877-a0b1-0dd96e92c380</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I haven&amp;#39;t tested, but it should work as long as you build it for the thingy board.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/211108?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 07:26:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:630cc5c8-8e0e-443f-a81d-4c3412d47460</guid><dc:creator>DennisNG</dc:creator><description>&lt;p&gt;HI, does this example work for thingy91 ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/199480?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 09:31:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9475bc54-5f2c-47b5-a168-199cd88af091</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please try the http_post sample attached below and see if you get the same result. I used NCS v.1.0.0 and &lt;a href="http://ptsv2.com"&gt;http://ptsv2.com&lt;/a&gt;&amp;nbsp;as a test server.&lt;/p&gt;
&lt;p&gt;Received POST request:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-50367047af064f6f8fe6cda6000b9091/pastedimage1563528266266v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Project:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-50367047af064f6f8fe6cda6000b9091/http_5F00_post.zip"&gt;devzone.nordicsemi.com/.../http_5F00_post.zip&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;d suggest that you create a new ticket for HTTPS as I don&amp;#39;t have experience with it.&amp;nbsp;Maybe this thread is helpful:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/48202/https-sample/"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/48202/https-sample/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/199036?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 14:29:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:056335ca-20a4-4be6-82b1-9c1635b2b135</guid><dc:creator>Gwen Stouthuysen</dc:creator><description>&lt;p&gt;Vidar,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying you approach that seams very logical to me but somehow my call does not reach the database.&lt;/p&gt;
&lt;p&gt;I will have to cover up some aspects but I know that that side of the story is simply operational: the server is there and accepts POST REST calls of this organisation (SIGFOX is using this port to send my data to me)&lt;/p&gt;
&lt;p&gt;I just want to avoid someone to start jamming my port for fun.&lt;/p&gt;
&lt;p&gt;I did set up the connection parameters, using the right url and port 443.&lt;/p&gt;
&lt;p&gt;Set up a template to generate the POST code:&lt;/p&gt;
&lt;p&gt;#define POST_TEMPLATE &amp;quot;POST %s HTTP/1.1\r\nHost: %s\r\naccept-encoding: gzip, deflate \r\nConnection: keep-alive\r\nAccept: \*/\* \r\nContent-Type: application/json\r\nContent-length: %d\r\ncache-control: no-cache\r\n%s&amp;quot;&lt;/p&gt;
&lt;p&gt;which results in:&lt;/p&gt;
&lt;p&gt;POST /REST/MCS1608 HTTP/1.1&lt;br /&gt;Host:&amp;nbsp;xxxxx.xxx&lt;br /&gt;accept-encoding: gzip, deflate&lt;br /&gt;Connection: keep-alive&lt;br /&gt;Accept: */*&lt;br /&gt;Content-Type: application/json&lt;br /&gt;Content-length: 79&lt;br /&gt;cache-control: no-cache&lt;br /&gt;{&amp;quot;device&amp;quot;: &amp;quot;D2078B&amp;quot;,&amp;quot;timestamp&amp;quot;:&amp;quot;1563365148&amp;quot;,&amp;quot;data&amp;quot;:&amp;quot;a318e451a084f800f9004e0d&amp;quot;}&lt;/p&gt;
&lt;p&gt;Next I created a function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void app_http_post(void){
	struct sockaddr_in local_addr;
	struct addrinfo *res;
	local_addr.sin_family = AF_INET;
	local_addr.sin_port = htons(0);
	local_addr.sin_addr.s_addr = 0;

	printk(&amp;quot;HTTP POST example\n\r&amp;quot;);

	int err = getaddrinfo(HTTP_HOST, NULL, NULL, &amp;amp;res);

	printk(&amp;quot;getaddrinfo err: %d\n\r&amp;quot;, err);
	((struct sockaddr_in *)res-&amp;gt;ai_addr)-&amp;gt;sin_port = htons(HTTP_PORT);

    /*Prepare POST request*/
    char send_buf[500];
    snprintf(send_buf, 500, POST_TEMPLATE, HTTP_PATH, HTTP_HOST, strlen(TEST_STRING), TEST_STRING);
    int send_data_len = strlen(send_buf);

    printk(&amp;quot;POST code:\n\r%s\n\n\r&amp;quot;, send_buf);

    /*Open a Socket*/
    int client_fd = socket(AF_INET, SOCK_STREAM, 0);

	printk(&amp;quot;client_fd: %d\n\r&amp;quot;, client_fd);
	err = bind(client_fd, (struct sockaddr *)&amp;amp;local_addr,
		   sizeof(local_addr));
	printk(&amp;quot;bind err: %d\n\r&amp;quot;, err);

    /*Send post request*/
    int num_bytes = send(client_fd, send_buf, send_data_len, 0);

	printk(&amp;quot;send err: %d\n\r&amp;quot;, num_bytes);

	int tot_num_bytes = 0;

    do {
        num_bytes =	blocking_recv(client_fd, recv_buf, RECV_BUF_SIZE, 0);
	    tot_num_bytes += num_bytes;

	    if (num_bytes &amp;lt;= 0) {
		    break;
		}
	    printk(&amp;quot;%s&amp;quot;, recv_buf);
	  } while (num_bytes &amp;gt; 0);

	printk(&amp;quot;\n\rFinished. Closing socket&amp;quot;);
	freeaddrinfo(res);
	err = close(client_fd);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But I&amp;#39;m not sure whether all is OK as my POSTed information does not go through.&lt;/p&gt;
&lt;p&gt;I get no answer from the server (I know when something is wrong the server still answers with a fault code)&lt;/p&gt;
&lt;p&gt;send err: -1&lt;/p&gt;
&lt;p&gt;I tried with httpbin.org and there the result was the same: no result.&lt;/p&gt;
&lt;p&gt;with port 80 the result is the same, so I assume the problem is deeper than not being able to achieve an HTTPS call.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/182161?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2019 14:57:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee0e255b-6ba6-4590-aaa3-822023422209</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure if it&amp;#39;s possible to port libcurl to nRF9160, but you can use the socket API to make HTTP requests. A colleague has made a HTTP example using the Socket API that&amp;#39;s available here:&amp;nbsp;&lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/http"&gt;https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/http&lt;/a&gt;. This sample demonstrates how you can send a GET request. For POST requests you can use the following template along with snprintf/sprintf.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define HTTP_HOST example.com
#define HTTP_PATH &amp;lt;post url&amp;gt;
#define TEST_STRING = &amp;quot;Hello from nrf91&amp;quot;

#define POST_TEMPLATE &amp;quot;POST %s? HTTP/1.1\r\n&amp;quot;\
		&amp;quot;Host: %s\r\n&amp;quot;\
		&amp;quot;Connection: keep-alive\r\n&amp;quot;\
		&amp;quot;Content-Type: text/plain\r\n&amp;quot;\
		&amp;quot;Content-length: %d\r\n\r\n&amp;quot;\
		&amp;quot;%s&amp;quot;

/*Prepare POST request*/
send_data_len = snprintf(send_buf,
				         500, /*total length should not exceed MTU size*/
				         POST_TEMPLATE, HTTP_PATH,
				         HTTP_HOST, strlen(TEST_STRING),
				         TEST_STRING);

/*Send post request*/
blocking_send(client_fd, send_buf, send_data_len, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Edit: defined TEST_STRING&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make http post. No libcurl?</title><link>https://devzone.nordicsemi.com/thread/182068?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2019 10:50:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a869bf5-f2b8-4df6-bfd5-e8dcb8775443</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;Hi Moshe,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you share the code?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thanks,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;hng&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>