0

My question is very simple : is it possible to send a HTTP request from the *nix command line specifying a file, containing all the parameters, as an argument?

In REST APIs documentation, we often see that kind of specification

POST /oauth/token HTTP/1.1
Host: api.example.com
Content-Type: application/x-www-form-urlencoded

grant_type=password
  &client_id=<API_KEY>
  &client_secret=<API_SECRET>
  &username=<USER_USERNAME>
  &password=<USER_PASSWORD>

To avoid command lines that are very long and uneasy to edit, is it possible to put these informations in a file, in the above-mentioned format (which seems pretty standard) ? Ideally something with curl that would look like

curl --input-file myparameters.txt

I could not find such feature in curl documentation. Maybe with another command line tool? Thanks in advance.

  • have you tried input redirection? curl << paramfile – Frank Thomas Mar 24 '15 at 11:52
  • Thanks for your reply. I've tried it and it seems curl doesn't recognize that kind of file as a direct input – benoit Mar 24 '15 at 12:03
  • How about if you write the line GET / in a file a.a and do cat a.a | nc 74.125.138.106 80 That does work. Then maybe you can add headers to the file a.a ? – barlop Mar 24 '15 at 16:47
-1

If you're doing it from the UNIX command line, I dont' see why it wouldn't be so difficult to create a script which essentially parses your text input and then converts it into something that curl can use at the CLI. For instance, if a line starts with 'HOST' you can use sed to create a string which represents the hostname at the end of a line which represents curl program input. The same goes for the rest.

Else, why don't you try just writing a simple client/wrapper program/script yourself? It's not that difficult, just tedious and you can always ask back here for more help (I did something similar a long while ago to test firewall setup).

http://alternativeto.net/software/curl/

  • -1 you haven't really solved anything here, your "answer" may be ok as a comment. If you think it wouldn't be so difficult then you can provide an actual answer. – barlop Mar 24 '15 at 12:32
  • well thanks for your reply but my question was not about how to develop a tool to handle parameters in a file but to know if such a tool already existed – benoit Mar 24 '15 at 15:52
  • furthermore, any answer related to developing a tool should be on stackoverflow, though this answer would be no good there either 'cos it doesn't even answer that either. – barlop Mar 24 '15 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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