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

标签 c# php asp.net apache asp.net-web-api

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

相关文章:

php - 选择数据然后从数组中匹配

c# - Gridview数据绑定(bind)下拉列表和更新

javascript - 在数据列表中重复jquery datepicker

c# - OrganizationServiceContext.CreateQuery 与获取

C# 和长 SQL Server 查询,正确的方法是什么?

php - sql查询显示每个结果3次而不是只一次

php - 在所有浏览器打开的选项卡中更改页面标题

asp.net - 如何在 ASP.NET 页面和 Windows 服务之间有效地传递不频繁的消息?

C#6.0 字符串插值本地化

c# - 用于存储加密字段数据的最佳数据类型