I
I
Ivan Sushkov2017-02-01 19:25:48
PHP
Ivan Sushkov, 2017-02-01 19:25:48

Why doesn't CURL render the body?

The story begins with an attempt to send a file to a service. The service expects file(binary), so I do something like this:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
      'file' => new CurlFile($_FILES['image']['tmp_name'])
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);

In response to such a request, the service responds:
status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Required request body is missing:

What could be causing this behavior?
I entered the path to $_FILES['image']['tmp_name'] manually - it did not change the final error much. Maybe someone has thoughts in which direction to direct reflections and what I'm wrong about. I will be very grateful.
PHP version 5.5.9 . The "@".$_FILES['image']['tmp_name'] method also had to be tested.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2017-02-01
@jamesgoodwin

1. The service expects a single field file? No others?
2. If instead of $_FILES[] we just take some test file, what is, for example, in the same directory with the script?
3. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true) try.
4. See curl_getinfo() for details.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question