简体   繁体   中英

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:

"Message":"The requested resource does not support http method '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. The web service has to be accessed via POST.

Have a look at here for details on how to create a POST request via curl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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