PHP / ASP.NET MVC Web-Api Кто-то знает, как использовать PHP для вызова WEBAPI с помощью POST

Пожалуйста, помогите мне рассказать, как использовать PHP для вызова asp.net web api, спасибо.
извините, я раньше не использовал PHP, поэтому я просто хочу использовать очень простой код для вызова серверной части WebAPI.
Спасибо за ваше терпение, если вы прочитали мой вопрос до конца.

PS: я сделал эту проблему и поделился, как справиться с этим следующим образом

Как мне установить CURL в Windows?

этот URL может быть решен с моей проблемой, я постараюсь сделать это. спасибо всем

меры

1. to check your php.ini address ,
2.Search or find the following : ‘;extension=php_curl.dll’
3.Uncomment this by removing the semi-colon ‘;’ before it
4.Save and Close PHP.ini
5.Restart Apache

адрес для всех
http://www.tomjepson.co.uk/enabling-curl-in-php-php-ini-wamp-xamp-ubuntu/

1

Решение

Обычно вызов осуществляется через расширение curl (я советую вам уделить время, чтобы прочитать об этом). Вот функция, которую я использую для выполнения запросов curl (в json):

function make_curl_request()
{
$data = []; // data to send
$data_string = json_encode($data);
$ch = curl_init("http://localhost:8000/function");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

//execute post
$result = curl_exec($ch);


curl_close($ch);
$result = json_decode($result,true);
print_r($result);

}
1

Другие решения

Вам нужно использовать curl для этого:

$curl = curl_init('http://myapi.com/');
$post_data = array(
'post_var_1' => 'foo',
'post_var_1' => 'bar'
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$curl_response = curl_exec($curl);
curl_close($curl);
if ($curl_response === false) {
// handle api call error here ...
} else {
// get your results from $curl_response here
}
1

Как мне установить cURL в Windows?

этот URL может быть решен с моей проблемой, я постараюсь сделать это. спасибо всем

меры

1.<?php echo phpinfo(); ?>  To check your php.ini address ,
2.Search or find the following : ‘;extension=php_curl.dll’
3.Uncomment this by removing the semi-colon ‘;’ before it
4.Save and Close PHP.ini
5.Restart Apache

адрес для всех
http://www.tomjepson.co.uk/enabling-curl-in-php-php-ini-wamp-xamp-ubuntu/

1