2

I want to submit a form of with the following information:

<form enctype="mutlipart/form-data" method="post" action="/command">
  <input tyep="submit" value=" Generate Snapshot " name="GENERATE_SNAPSHOT" ></input>
</form>

I try to make such request using a webpage (chrome), under the "network" tab, I observe that:

`request URL:http://170.10.10.20:8888/command`
Request Mehthod:POST
Status Code:200 OK

Request Payload:
-------WebKitFormBoundaryLhRbxtNE7XU71JAD
Content-Disposition: form-data; name="GENERATE_SNAPSHOT"

 Generate Snapshot
-------WebKitFormBoundaryLhRbXtNE7Xu71JAD----

My Curl command looks like the following:

curl -f "GENERATE_SNAPSHOT=%20Generate%20Snapshot%20" http://170.10.10.20:8888/command

But the return value looks inaccruate because it returns me something that looks like :

<html><head><head><META HTTP -QUIIV="EXPIRES" CONTENT="TEXT/HTML; 
.....(and so on)

Why this is not working?

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
andy_ttse
  • 23
  • 1
  • 3
  • 2
    Use spaces instead of `%20`, try `curl -F "GENERATE_SNAPSHOT= Generate Snapshot " http://170.10.10.20:8888/command` – Dan Mar 28 '15 at 06:38

3 Answers3

1

Because you are not sending a POST request but a GET request and what should have been the body of you POST request is ignored by curl. Furthermore, option -f is used to silently fail on server errors, you are looking for -F which forces usage of Content-type: multipart/form-data within your POST request.

Use instead :

curl -XPOST \
    -F 'GENERATE_SNAPSHOT= Generate Snapshot ' \
    "http://170.10.10.20:8888/command"
Xavier Lucas
  • 13,095
  • 2
  • 44
  • 50
0

It's -F not -f.
Also in Chrome you can right click on the request in the network tab and "Copy as cURL".
That will add the exact request Chrome did to your clipboard, ready to be executed via cURL.

faker
  • 17,496
  • 2
  • 60
  • 70
0

To do a POST you need to set the request method.

curl -X POST -f ... http://...
bahamat
  • 6,263
  • 24
  • 28