HTTP POST request using Curl: why nothing works

curlhttp

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?

Best Answer

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"