Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In , this code posts String to post to

curl -d "String to post" ""

NOTE: You should use as the URL to POST to, without any change.

I think all other languages that I have knowledge in need a lot more code than this. I'm not blaming other languages. Let's see the interesting answers that reduce the effort.

Your task is to write the shortest code possible to send a POST request to a sample server,, and the request data should be the string String to post.

share|improve this question
It's not clear that the title and the body are asking for the same thing, let alone what you consider to be sufficient and necessary to qualify as a solution. – Peter Taylor Feb 22 '14 at 12:42
Dont you understand the question? this is the best i can explain. the title and body are clear for me – Viswanath Lekshmanan Feb 22 '14 at 12:45
@Peter Taylor I have edited the question to try to make it more clear. – ace Feb 22 '14 at 12:52
Thanks for that :) – Viswanath Lekshmanan Feb 22 '14 at 12:55
Another one of the same size: POST<<<'String to send'. (POST is either a stand-alone script or symlink to lwp-request, a command line tool delivered with the LWP perl module.) – manatwork Feb 22 '14 at 14:08

19 Answers 19

Bash: 90 characters

No external tools, just pure bash.

echo 'POST /target HTTP/1.0

String to post'>/dev/tcp/
share|improve this answer
That's Bash running on Linux. I have a Bash commandline for my windows box but do not have /dev – Jerry Jeremiah Jan 27 '15 at 4:07
Not sure whether it depends on /dev/, but /dev/tcp/ doesn't exist anywhere – it is just Bash's own syntax for opening a TCP connection. Personally I would expect it to work regardless the presence of /dev/. It certainly works in Cygwin, but I have a feeling that you use MinGW. Could you please @JerryJeremiah post us some details about this? Like Bash's version, the package from which it comes, what actually happens when you run my posted code. (By the way, should not happen anything visible – Bash just connects, transfers, disconnects, exits with 0.) – manatwork Jan 27 '15 at 9:30
I'm astonished to announce this works - even without a /dev/ directory! I saw the /dev/ and jumped to a stupid conclusion. I am running the bash version 3.1.17 from the bmatzelle/gow github repo. – Jerry Jeremiah Jan 28 '15 at 3:01
For enybody else that never knew you could do that, look here:… – Jerry Jeremiah Jan 28 '15 at 3:05

Rebol (51 chars)

write"String to post"

Above works in Rebol 3. Below is a Rebol 2 version (63 chars):

read/custom[post"String to post"]
share|improve this answer

Javascript, 84

with(XMLHttpRequest())open('POST','//'),send('String to post')

Try in the console of any page served over plain HTTP.

share|improve this answer
I think you can replace with :// – Clyde Lobo Feb 24 '14 at 9:26
@ClydeLobo. Can you get rid of the www? I don't see how that's legitimate. – TRiG Feb 25 '14 at 3:27
@TRiG OK. It's now fully compliant with the question. – Toothbrush Feb 26 '14 at 13:51

Powershell v3 - 58

iwr -b "String to post"-me 3
share|improve this answer

newLISP - 58 characters

(post-url """String to post")
share|improve this answer

Smalltalk (Smalltalk/X), 64 71

HTTPInterface post:''with:'String to post'
share|improve this answer
this contains 71 characters – Viswanath Lekshmanan Feb 23 '14 at 5:05
sorry - you're right - I tested (and counted) another string to post. Embarrased! – blabla999 Feb 24 '14 at 21:11

Bash - 63 chars

wget --post-data="String to post"
share|improve this answer

PHP - 100 bytes

<?fwrite(fsockopen('',80),'POST /target HTTP/1.0

String to post');

I apologize for any similarities to manatwork's bash solution, but I believe that this is the shortest way to do it.

share|improve this answer
There is a solution I wasn't expecting. Well done! – Ismael Miguel Feb 24 '14 at 21:03
You need to use, not – Toothbrush Feb 27 '14 at 12:36
@toothbrush they do resolve to the same IP. But I agree that for fairness, everyone should be using exactly the same URL (and, that the question was modified after this was posted to make that explicit). – primo Feb 27 '14 at 13:18
@primo Yes, that's true. However, the question did originally say that the code should POST to – Toothbrush Feb 27 '14 at 13:32

Lua (texlua), 73 bytes

require("socket.http").request("","String to post")
share|improve this answer
The question said to POST to – Toothbrush Feb 27 '14 at 13:34
@toothbrush: Thanks, I missed www.. I have updated the answer and also changed .org to .com. http:// can be omitted, because it is the default. – Heiko Oberdiek Feb 27 '14 at 13:37
Great! I know that you can omit the http:// part - I wasn't saying to include it. – Toothbrush Feb 27 '14 at 13:48

Game Maker Language (GMStudio), 66

http_post_string("","String to post")
share|improve this answer

VBScript: 114 characters

dim x:set x=createobject("MSXML2.ServerXMLHTTP")"post",""
x.send"String to post"
share|improve this answer
Slightly smaller: With CreateObject("MSXML2.ServerXMLHTTP"):.Open"POST","":.Se‌​nd"String to post":End With – Toothbrush Feb 22 '14 at 20:35
Yes, you're right. Thank you for your comment! – Aleksey Bykov Feb 22 '14 at 20:55
The question now states that you need to POST to Note the www. part. – Toothbrush Feb 27 '14 at 13:34

Python 2: 80 chars

Just using the standard library:

import urllib2 as u
u.urlopen("","String to post")

For an extra char, you can make the import less unusual.

import urllib2
urllib2.urlopen("","String to post")
share|improve this answer
If you want to gain another char: __import__('urllib2').urlopen("","String to post") – nutria Feb 23 '14 at 18:19
Sneaky. I like it – James_pic Feb 24 '14 at 22:28

Tcl - 85 chars

package require http
http::geturl "//" -query "String to post"
share|improve this answer

Actionscript 3, 201

var aRV:URLVariables = new URLVariables();
aRV.STRING = "my string";
var aR:URLRequest = new URLRequest("");
aR.method = URLRequestMethod.POST; = aRV;
var aL = new URLLoader();

no error handling

share|improve this answer

jQuery, 58

$.post("", "String to post");

share|improve this answer
jQuery isn't a programming language... – Downgoat Jan 30 at 2:50

Batch/Powershell - 118 Chars

If you need to post from a Windows batch file or avoid changing ExecutionPolicy:

powershell -Command "(New-Object Net.WebClient).UploadString('', 'p1=String%20to%20Post')"
share|improve this answer

PHP, 198 bytes

This is shamefully large...:

<?fopen('','rb',0,stream_context_create(array('http'=>array('method'=>'POST','header'=>'Content-Type: application/x-www-form-urlencoded','content'=>'String to post'))));

At least I answered!

share|improve this answer
The second one complains that the HTTP wrapper does not support writable connections. If it were to do anything, it would attempt to overwrite the contents of the http request with the given string. – primo Feb 24 '14 at 5:04
That's why I said that I'm not sure if it works. But I will remove the second answer. – Ismael Miguel Feb 24 '14 at 13:39
The answer was removed, but still can be seen on the edit option. – Ismael Miguel Feb 24 '14 at 13:40
But surely the Content-Type is text/plain, not application/x-www-form-urlencoded? – TRiG Feb 25 '14 at 3:30
application/x-www-form-urlencoded is the default mime-type to send data to a server, text/plain is the default mime-type to receive any non-binary text without a declared mime-type. – Ismael Miguel Feb 25 '14 at 12:23

Bash, 69 bytes

lwp-request -m POST -b "String to post"

You can read about the lwp-request command here:

I think that the answer given by @manatwork is a much more neat and compatible version.

share|improve this answer

𝔼𝕊𝕄𝕚𝕟, 47 chars / 51 bytes (noncompetitive)

ɟŏ`//⍪String to post

Try it here (Firefox only).

Uses jQuery's post function.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.