Skip to main content
 首页 » 编程设计

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

2024年06月20日47zhujiabin

请帮我告诉我如何使用 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); 
 
  }