curl / Mailing Lists / curl-library / Single Mail

curl-library

(no subject)

From: Greg Stewart via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 18 Apr 2017 09:09:15 -0600

Thanks for the help. From the command line, I did this:

curl -F uri='' -F username=ubnt -F password=ubnt
https://192.168.135.22/login.cgi -k --trace-ascii logfile.txt --cookie-jar
cookies.txt --location

The uri always seems to be empty when I check it with httpfox. The terminal
prints:

<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

 <head>

  <title>417 - Expectation Failed</title>

 </head>

 <body>

  <h1>417 - Expectation Failed</h1>

 </body>

</html>

The logfile.txt contains:

== Info: Trying 192.168.135.22...

== Info: TCP_NODELAY set

== Info: Connected to 192.168.135.22 (192.168.135.22) port 443 (#0)

== Info: TLS 1.0 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA

== Info: Server certificate: UBNT

=> Send header, 217 bytes (0xd9)

0000: POST /login.cgi HTTP/1.1

001a: Host: 192.168.135.22

0030: User-Agent: curl/7.50.3

0049: Accept: */*

0056: Content-Length: 340

006b: Expect: 100-continue

0081: Content-Type: multipart/form-data; boundary=--------------------

00c1: ----16cb796ffbb7a6ab

00d7:

<= Recv header, 33 bytes (0x21)

0000: HTTP/1.1 417 Expectation Failed

<= Recv header, 25 bytes (0x19)

0000: Content-Type: text/html

<= Recv header, 21 bytes (0x15)

0000: Content-Length: 363

<= Recv header, 19 bytes (0x13)

0000: Connection: close

<= Recv header, 37 bytes (0x25)

0000: Date: Tue, 18 Apr 2017 14:09:48 GMT

<= Recv header, 25 bytes (0x19)

0000: Server: lighttpd/1.4.31

<= Recv header, 2 bytes (0x2)

0000:

<= Recv data, 363 bytes (0x16b)

0000: <?xml version="1.0" encoding="iso-8859-1"?>.<!DOCTYPE html PUBLI

0040: C "-//W3C//DTD XHTML 1.0 Transitional//EN". "http://www.

0080: w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.<html xmlns="http

00c0: ://www.w3.org/1999/xhtml" xml:lang="en" lang="en">. <head>. <ti

0100: tle>417 - Expectation Failed</title>. </head>. <body>. <h1>417

0140: - Expectation Failed</h1>. </body>.</html>.

== Info: Curl_http_done: called premature == 0

== Info: Closing connection 0

On Tue, 18 Apr 2017, Greg Stewart via curl-library wrote:

The boundary value changes with each request. I tried this command from the
> command line just to see if I could get it working from there.
>
> curl -X POST -H "Content-Type: multipart/form-data;
> boundary=----------------------------8836643981898118181802691882"
> --data-binary @test.txt https://192.168.135.22/login.cgi -k
>

You want -F and let curl handle the boundary string by itself:

 curl -F uri=moo -F username=foobar -F password=secret
 https://192.168.135.22/login.cgi -k

Add "--trace-ascii logfile.txt" to the command line to save the entire
request and verify that it actually looks like you want it to look.

Then you *probably* want to add "--cookie-jar cookies.txt" to the command
line as well to save cookies from the response, as that is probably how it
saves the logged in session. You then use "--cookie cookies.txt" in
subsequent requests to reuse that session (you probably want to use both
options since subsequent reqests might updated the cookies as well).

Finally, when you post the login data the server often redirects you to a
new page and curl doesn't following redirects by default. Use --location
for that.

(and avoid -X POST, that will only cause you grief)

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-18