Note that there are some explanatory texts on larger screens.

plurals
  1. POCurl loses body when a POST redirected from http to https
    primarykey
    data
    text
    <p>I'm trying to use curl 7.23.1 to POST some data to my server (which runs an <code>nginx</code> server). When this <code>nginx</code> is queried using <code>http://</code>, it redirects to <code>https://</code> if it can (if it has keys and all the mambo-jumbo)</p> <p>It looks like curl is doing something... odd. For compatibility reasons, my script (the thing that runs <code>curl</code>) is sending its requests to <code>http://</code>, but when it hits a server that has <code>https://</code> available (and therefore, gets redirected), the body in the <code>POST</code> request disappears. </p> <p>I'm trying to upload a bunch of text using <a href="http://curl.haxx.se/docs/manpage.html#--data-urlencode" rel="nofollow">--data-urlencode name@filename</a> option. Basically, I run an script, dump its output in the file <code>/tmp/checkin/cmd_result</code>, and I want to upload that as the "data" attribute of the request:</p> <pre><code>curl --max-time 30 --silent --location-trusted \ --insecure --write-out "%{http_code}" --request POST \ --data-urlencode "data@/tmp/checkin/cmd_result" \ "http:/myserver/command_reply?command_id=524729ce93bc63292c1c9831" \ --trace-ascii /tmp/command_response_trace.log \ --output /tmp/checkin/cmd_res_resp --connect-timeout 10 </code></pre> <p>But the redirection seems to strip the body. If I send my data directly to <code>https://</code>, everything works like a charm. Adding <code>-L</code> (<code>--location</code>) or <code>--location-trusted</code> to the curl instruction doesn't seem to fix the issue.</p> <p>Has someone experienced the same issue? Any help will be deeply appreciated.</p> <p>PS:</p> <p>This is the trace <code>curl</code> outputs (I've cleaned it a bit):</p> <pre><code>=&gt; Send header, 300 bytes (0x12c) 0000: POST /command_reply?&amp;command_id=52 0040: 4729ce93bc63292c1c9831 HTTP/1.1 0061: User-Agent: curl/7.23.1 (mips-openwrt-linux-gnu) libcurl/7.23.1 00a1: OpenSSL/1.0.1c zlib/1.2.7 00e4: Content-Length: 356 00f9: Content-Type: application/x-www-form-urlencoded 012a: =&gt; Send data, 356 bytes (0x164) 0000: data=PING%20google.coms%0A &lt;= Recv header, 32 bytes (0x20) 0000: HTTP/1.1 302 Moved Temporarily &lt;= Recv header, 22 bytes (0x16) 0000: Server: nginx/1.1.19 &lt;= Recv header, 37 bytes (0x25) 0000: Date: Sat, 28 Sep 2013 19:11:27 GMT &lt;= Recv header, 25 bytes (0x19) 0000: Content-Type: text/html &lt;= Recv header, 21 bytes (0x15) 0000: Content-Length: 161 &lt;= Recv header, 24 bytes (0x18) 0000: Connection: keep-alive &lt;= Recv header, 120 bytes (0x78) 0000: Location: https://myserver/sensor/command_reply?command_id 0040: =524729ce93bc63292c1c9831 &lt;= Recv header, 2 bytes (0x2) 0000: &lt;= Recv data, 161 bytes (0xa1) 0000: &lt;html&gt; 0008: &lt;head&gt;&lt;title&gt;302 Found&lt;/title&gt;&lt;/head&gt; 002f: &lt;body bgcolor="white"&gt; 0047: &lt;center&gt;&lt;h1&gt;302 Found&lt;/h1&gt;&lt;/center&gt; 006c: &lt;hr&gt;&lt;center&gt;nginx/1.1.19&lt;/center&gt; 008f: &lt;/body&gt; 0098: &lt;/html&gt; == Info: SSLv3, TLS handshake, Client hello (1): =&gt; Send SSL data, 189 bytes (0xbd) 0000: ..... == Info: SSLv3, TLS handshake, Server hello (2): &lt;= Recv SSL data, 90 bytes (0x5a) 0000: ..... == Info: SSLv3, TLS handshake, CERT (11): &lt;= Recv SSL data, 3227 bytes (0xc9b) 0000: .....?. == Info: SSLv3, TLS handshake, Server key exchange (12): &lt;= Recv SSL data, 525 bytes (0x20d) 0000: .^~... == Info: SSLv3, TLS handshake, Server finished (14): &lt;= Recv SSL data, 4 bytes (0x4) 0000: .... == Info: SSLv3, TLS handshake, Client key exchange (16): =&gt; Send SSL data, 134 bytes (0x86) 0000: ...' == Info: SSLv3, TLS change cipher, Client hello (1): =&gt; Send SSL data, 1 bytes (0x1) 0000: . == Info: SSLv3, TLS handshake, Finished (20): =&gt; Send SSL data, 16 bytes (0x10) 0000: .... == Info: SSLv3, TLS change cipher, Client hello (1): &lt;= Recv SSL data, 1 bytes (0x1) 0000: . == Info: SSLv3, TLS handshake, Finished (20): &lt;= Recv SSL data, 16 bytes (0x10) 0000: ... =&gt; Send header, 230 bytes (0xe6) 0000: POST /sensor/command_reply?command_id=52 0040: 4729ce93bc63292c1c9831 HTTP/1.1 0061: User-Agent: curl/7.23.1 (mips-openwrt-linux-gnu) libcurl/7.23.1 00a1: OpenSSL/1.0.1c zlib/1.2.7 00bc: Host: myserver 00d7: Accept: */* 00e4: &lt;= Recv header, 17 bytes (0x11) 0000: HTTP/1.1 200 OK &lt;= Recv header, 22 bytes (0x16) 0000: Server: nginx/1.1.19 &lt;= Recv header, 37 bytes (0x25) 0000: Date: Sat, 28 Sep 2013 19:11:27 GMT &lt;= Recv header, 47 bytes (0x2f) 0000: Content-Type: application/json; charset=UTF-8 &lt;= Recv header, 20 bytes (0x14) 0000: Content-Length: 22 &lt;= Recv header, 24 bytes (0x18) 0000: Connection: keep-alive &lt;= Recv header, 2 bytes (0x2) 0000: &lt;= Recv data, 22 bytes (0x16) 0000: {"r": 200, "data": {}} == Info: SSLv3, TLS alert, Client hello (1): =&gt; Send SSL data, 2 bytes (0x2) 0000: .. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload