简体   繁体   English

在php中使用C#Rest Web服务

[英]consume c# rest web service in php

I am trying to connect to ac# rest web service by php, but when I execute the below code this error happened: 我正在尝试通过php连接到ac#rest Web服务,但是当我执行以下代码时,发生了此错误:

"Message":"The requested resource does not support http method 'GET'". “消息”:“请求的资源不支持http方法'GET'”。

Could anybody help me about this error? 有人可以帮我解决这个错误吗?

<?php 
$url="https://example/login";
$username='user';
$password='pass';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD,$username':'$password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$out = curl_exec($ch);
print "error:" . curl_error($ch) . "<br />";
echo $out;
curl_close($ch);
?>

By default, curl is executing the request via HTTP GET. 默认情况下, curl通过HTTP GET执行请求。 The web service has to be accessed via POST. 必须通过POST访问Web服务。

Have a look at here for details on how to create a POST request via curl. 此处查看有关如何通过curl创建POST请求的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM