gpt4 book ai didi

c# - PHP/ASP.NET MVC Web-Api 有人知道如何使用PHP通过POST调用WEBAPI

转载 作者:太空宇宙 更新时间:2023-11-03 23:36:59 24 4
gpt4 key购买 nike

请帮我告诉我如何使用 PHP 调用 asp.net web api,谢谢。抱歉,我以前没有使用过 PHP,所以我只想使用非常简单的代码来调用 WebAPI 的服务器端。
如果您已经阅读完我的问题,感谢您的耐心等待。

PS: I have done this issue and sharing how to handle this as following

如何在 Windows 上安装 CURL?

这个网址可以解决我的问题,我会尽力去做。谢谢大家

步骤

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/

最佳答案

通常调用是通过 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);

}

关于c# - PHP/ASP.NET MVC Web-Api 有人知道如何使用PHP通过POST调用WEBAPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30299796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com