1

I am trying to connect to a c# 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);
?>
Andy Korneyev
  • 25,238
  • 15
  • 65
  • 65
pooya
  • 11
  • 1

1 Answers1

0

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.

Community
  • 1
  • 1
dhh
  • 4,030
  • 8
  • 40
  • 56