post-url question

Q&A's, tips, howto's
Locked
Robert Gorenc
Posts: 12
Joined: Tue Oct 27, 2009 9:01 pm
Location: Croatia

post-url question

Post by Robert Gorenc »

dear all,
I'm new to this forum and Lisp also, I would like to send greetings to all!
I have a question about configuring header and parameters send in post-url.

when sending (post-url "http://ip.addr/cli/cgi-bin/exe.pl"
"param1=v1&param2=v2&param3=v3" "text/plain" 5000 "Content-Length: 50\r\nAuthorization: Basic encripted-user-psswd\r\n\r\n" )

in wireshark it looks very strange:
first packet:
POST /cli/cgi-bin/exe.pl HTTP/1.1\r\n
Request Method: POST
Request URI: /cli/cgi-bin/exe.pl
Request Version: HTTP/1.1

second:
Hypertext Transfer Protocol
Host: 10.243.117.12\r\n
Content-Length: 50
Authorization: Basic encrypted-user-psswd\r\n
\r\n
Data (50 bytes)

0000 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 63 6c 6f 73 Connection: clos
0010 65 0d 0a 43 6f 6e 74 65 6e 74 2d 74 79 70 65 3a e..Content-type:
0020 20 0d 0a 43 6f 6e 74 65 6e 74 2d 6c 65 6e 67 74 ..Content-lengt
0030 68 3a h:
Data: 436F6E6E656374696F6E3A20636C6F73650D0A436F6E7465...
Hypertext Transfer Protocol
Data (119 bytes)

0000 20 31 31 31 0d 0a 0d 0a 6e 65 5f 6e 61 6d 65 3d 111....ne_name=
0010 6d 73 63 31 26 74 61 73 6b 5f 74 79 70 65 3d 54 msc1&task_type=T
...
0060 65 3d 73 74 61 74 73 73 70 26 6d 65 74 68 6f 64 e=statssp&method
0070 3d 69 6e 73 69 64 65 =inside
Data: 203131310D0A0D0A6E655F6E616D653D6D73633126746173...

and there is response from server something like wrong user authorisation or similar...
If I omit in header part Content-Length, then server return error that content length is missing.

I would like to get something like this:
Hypertext Transfer Protocol
POST http://10.243.117.12/cli/cgi-bin/exe.pl HTTP/1.1\r\n
Request Method: POST
Request URI: http://10.243.117.12/cli/cgi-bin/exe.pl
Request Version: HTTP/1.1
Host: 10.243.117.12\r\n
Accept-Encoding: identity\r\n
Content-Length: 111
Authorization: Basic cmdvcmVuYzo3R2VsaXB0ZXI3\r\n
\r\n
folowed with:
Hypertext Transfer Protocol
Data (111 bytes)

0000 6e 65 5f 6e 61 6d 65 3d 4d 53 43 31 26 74 61 73 ne_name=MSC1&tas
0010 6b 5f 74 79 70 65 3d 54 41 53 4b 26 75 67 5f 6e k_type=TASK&ug_n
...
0060 70 26 6d 65 74 68 6f 64 3d 69 6e 73 69 64 65 p&method=inside
Data: 6E655F6E616D653D4D534331267461736B5F747970653D54...
and after that is correct answer from server.

in python this can be done with request("POST", "http://ip.addr/cli/cgi-bin/exe.pl", params, headers)
describing params and headers as necessary.
Is it possible to get something like this with post-url?

Robert

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: post-url question

Post by Lutz »

This is how basic authorization is done for Twitter:

http://www.newlisp.org/syntax.cgi?code/twitter.txt

also referenced from here:

http://www.newlisp.org/index.cgi?Tips_and_Tricks

basically you have to Base 64 encode the authorization yourself:

Code: Select all

(set 'auth (append "Authorization: Basic " (base64-enc "john:secret") "\r\n"))
(get-url the-url 5000 auth)

ps: welcome to newLISP

Robert Gorenc
Posts: 12
Joined: Tue Oct 27, 2009 9:01 pm
Location: Croatia

Re: post-url question

Post by Robert Gorenc »

Thanks Lutz,
Actually, user and psswd encription was not problem. But after Your message, I looked again in my header in post-url and found if remove second pair of \r\n, than post-url works as expected!!!
the working method is now:
(post-url "http://ip.addr/cli/cgi-bin/exe.pl"
"ne_name=msc1&task_type=TASK&ug_name=rgorenc&NEInputMethod=ViaNEName&Dang_Task=ON&taskname=statssp&method=inside" "" 10000 "Authorization: Basic encripted user-psswd\r\n" ) !!

thanks again,
Robert

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Re: post-url question

Post by Kazimir Majorinc »

Hi Robert, I'm also from Croatia, Zagreb. Welcome.

Locked