S
S
semen79072017-08-13 12:40:06
PHP
semen7907, 2017-08-13 12:40:06

How to send a curl request via php?

A .py script is launched on the server that receives a curl request, the request itself: Tell me, how can I send this request using php? And how can I get and output a response from a .py script (json response) curl -F "[email protected]" http://127.0.0.1:5001

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2017-08-13
@semen7907

There is no such thing as a curl request. cURL is a utility for making http requests from the command line. PHP has an interface to the libcurl library :

$request = curl_init('http://127.0.0.1:5001/');

curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
    $request,
    CURLOPT_POSTFIELDS,
    array(
      'file' => '@' . realpath('image.jpg')
    )
);

curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($request);
curl_close($request);

M
Maksim Fedorov, 2017-08-13
@Maksclub

Documentation:
php.net/manual/ru/book.curl.php
Video tutorials:
https://www.youtube.com/watch?v=oVdwiuqeOt0&list=P...
https://www.youtube.com/watch ?v=qEpPbgwB8Q8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question