New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-json POST #71

Closed
Silex opened this Issue Mar 24, 2015 · 8 comments

Comments

Projects
None yet
3 participants
@Silex
Contributor

Silex commented Mar 24, 2015

Hello,

Is it possible to do non-json POST?

Here's what I tried:

POST http://someurl

field=test&field2=test2
@pashky

This comment has been minimized.

Owner

pashky commented Mar 24, 2015

It is

@Silex

This comment has been minimized.

Contributor

Silex commented Mar 24, 2015

Okay, I found a bug, but I'm not sure wether it's in restclient or if it's in url-retrieve... actually it might be both :)

Basically this request:

POST http://someurl

pwd=1234

Gives a Content-Length of 9 when it should be 8. I think the RFC allows for both (e.g with or without the newline), but the server I deal with only accepts the request when Content-Lenght is 8.

So my problem is that resclient-mode has the body of the request to be pwd=1234\n (9 chars) and that fails server-side, and if I modify it so entity is just pwd=1234 (8 chars) then it's url-retrieve which fails to send it because it doesn't include the final \r\n properly. I'm running emacs 25 and maybe the bug in url-retrieve was fixed, I'll try updating.

@pashky

This comment has been minimized.

Owner

pashky commented Mar 24, 2015

That's funny. I started googling about trailing newline and found this http://emacs.stackexchange.com/questions/5694/sending-application-x-www-form-urlencoded-data-with-restclient

You're not alone, apparently :) I'll check why url-retrieve fails if you strip newline.

@pashky

This comment has been minimized.

Owner

pashky commented Mar 25, 2015

Try last version. I've made it chop last newline from body by default. Let's keep it like this and see if anyone complains. Only last newline is removed, any extra ones will be sent.

@Silex

This comment has been minimized.

Contributor

Silex commented Mar 25, 2015

Hum... last version doens't seem to change anything. Here's how I test:

nc -l 8000
# Test
POST http://127.0.0.1:8000

pwd=1234
# Test2
POST http://127.0.0.1:8000

pwd=1234

I see that Content-Length is still 9. If I move the cursor right after the 4 and press delete a lot, and run it again then Content-Lenght is 8 but retrieve-url doesn't send the last \n meaning end of request and the server waits for it...

As I said earlier, maybe I should test with stock emacs24 first, because url-retrieve seems to behave wrongly.

@pashky

This comment has been minimized.

Owner

pashky commented Mar 25, 2015

I tried this (make sure you have no extra spaces after 4):

POST http://httpbin.org/post

pwd=1234
#

and I get this:

{
  "url": "http://httpbin.org/post",
  "origin": "91.206.0.43",
  "json": null,
  "headers": {
    "Mime-Version": "1.0",
    "Host": "httpbin.org",
    "Extension": "Security/Digest Security/SSL",
    "Content-Length": "8",
    "Accept-Charset": "utf-8;q=1, gb2312;q=0.5, iso-8859-1;q=0.5, big5;q=0.5, iso-2022-jp;q=0.5, shift_jis;q=0.5, euc-tw;q=0.5, euc-jp;q=0.5, euc-jis-2004;q=0.5, euc-kr;q=0.5, us-ascii;q=0.5, utf-7;q=0.5, hz-gb-2312;q=0.5, big5-hkscs;q=0.5, gbk;q=0.5, gb18030;q=0.5, iso-8859-5;q=0.5, koi8-r;q=0.5, koi8-u;q=0.5, cp866;q=0.5, koi8-t;q=0.5, windows-1251;q=0.5, cp855;q=0.5, iso-8859-2;q=0.5, iso-8859-3;q=0.5, iso-8859-4;q=0.5, iso-8859-9;q=0.5, iso-8859-10;q=0.5, iso-8859-13;q=0.5, iso-8859-14;q=0.5, iso-8859-15;q=0.5, windows-1250;q=0.5, windows-1252;q=0.5, windows-1254;q=0.5, windows-1257;q=0.5, cp775;q=0.5, cp850;q=0.5, cp852;q=0.5, cp857;q=0.5, cp858;q=0.5, cp860;q=0.5, cp861;q=0.5, cp863;q=0.5, cp865;q=0.5, cp437;q=0.5, macintosh;q=0.5, next;q=0.5, hp-roman8;q=0.5, adobe-standard-encoding;q=0.5, iso-8859-16;q=0.5, iso-8859-7;q=0.5, windows-1253;q=0.5, cp737;q=0.5, cp851;q=0.5, cp869;q=0.5, iso-8859-8;q=0.5, windows-1255;q=0.5, cp862;q=0.5, iso-2022-jp-2004;q=0.5, cp874;q=0.5, iso-8859-11;q=0.5, viscii;q=0.5, windows-1258;q=0.5, iso-8859-6;q=0.5, windows-1256;q=0.5, iso-2022-cn;q=0.5, iso-2022-cn-ext;q=0.5, iso-2022-jp-2;q=0.5, iso-2022-kr;q=0.5, utf-16le;q=0.5, utf-16be;q=0.5, utf-16;q=0.5, x-ctext;q=0.5",
    "Accept": "*/*"
  },
  "form": null,
  "files": null,
  "data": "pwd=1234",
  "args": null
}

I'm using GNU Emacs 24.4.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2014-11-21 and bundled url.el

Tried on nightly (GNU Emacs 25.0.50.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F34)) of 2015-03-25 on builder10-9.porkrind.org) too, works the same.

Have you tried to sending similar request with curl? Does it work with your server? Could you see any difference between what curl and url.el sends?

@Silex

This comment has been minimized.

Contributor

Silex commented Mar 25, 2015

I confirm your example works.

If I remove the ending #, then it sends the ending \n and Content-Length is 9. Maybe this is due because I have require-final-newline set to t.

Anyway this is enough for me to consider it fixed. Thank you!

@Silex Silex closed this Mar 25, 2015

@sachinpkale

This comment has been minimized.

sachinpkale commented Sep 23, 2016

How does this work if I have more than one parameter in data?

If I use something like this, it won't accept the second parameter due to the # after first parameter.

POST http://httpbin.org/post

pwd=1234
#
name=abc
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment