0

I am using curl and I would like to execute a HTTP PUT request by sending a --data-urlencode string and a --data-binary JSON file content. Is it possible to make that in the same curl command?

I tried the following

curl www.website.org --request PUT -H Content-Type: application/json --data-urlencode "key=sample_string" --data-binary @sample_file.json

but it seems do not work as expected: key=sample_string and sample_file.json content are not send at all.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user502052
  • 14,803
  • 30
  • 109
  • 188

1 Answers1

0

A couple of things here;

  1. Your curl request is missing double quotes for the headers. It should rather be:
curl www.website.org --request PUT -H "Content-Type: application/json" \
 --data-urlencode "key=sample_string" --data-binary @sample_file.json
  1. Your content-type is application/json which I hope is not "binary", so you should rather be using an appropriate type.

In any case, you should be able to find the submitted values using a simple php script as follows:

$putfp = fopen('php://input', 'r');
$putdata = '';
while($data = fread($putfp, 1024))
    $putdata .= $data;
fclose($putfp);

var_dump($putdata);

echo "---CONTENT_TYPE---\n";
var_dump($_SERVER['CONTENT_TYPE']);
Community
  • 1
  • 1
PCoder
  • 2,165
  • 3
  • 23
  • 32