I
I
Igor Vasiliev2019-07-30 16:31:00
PHP
Igor Vasiliev, 2019-07-30 16:31:00

How to send API link via POST request?

Hello.
--
I have an API link that writes the passed parameters to a database table.
I did it according to the php documentation (I can't use curl)
The principle I use is this:

...
$url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
...

There are no errors, nothing comes up. Sending via Ajax. The message on email comes, record in a DB does not arrive.
What's wrong? Why doesn't it send?
I inserted a direct link into the browser, the request is sent, the entry in the database appears. As you understand, a link with parameters.
Maybe this method is not suitable for this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question