Can anyone please tell me I have MVC 5(C#) API controller, I want access API data using PHP application with user authentication. (without user authentication my PHP code will work). I have already created user model and add top for the C# MVC Controller '[Authorize(Roles = "User")]' . I have already tested this user name & password it is working.
When I add these details with my PHP code, it did not work for me. It say "{"Message":"Authorization has been denied for this request."}" Could you please tell me, why was not working, also If not good my solution, please tell me best solution.
C# MVC Controller
[Authorize(Roles = "User")]
public class HolidayController : ApiController
{
return "value";
}
HTML
<form method="post" action="index.php" enctype="multipart/form-data">
Enter your Postcode:
<input type="text" name="search" id="txtSearch" value="" >
<input name="submit" type="submit" value="Search"/><br />
</form>
PHP Code
if(isset($_POST['submit']))
{
// Checking null values in message.
$value = $_POST['search'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.myname.com/api/Holiday?pcode='.$value.'');
curl_setopt($ch, CURLOPT_POST, 1);// set post data to true
curl_setopt($ch, CURLOPT_POSTFIELDS,'Email=name&Password=123456'); // post data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
$result = curl_exec($ch);
print_r($result);
$Locations = json_decode($json);
curl_close ($ch);
foreach($Locations as $location)
{ echo $location->SubName. }
}
?>
It will print {"Message":"Authorization has been denied for this request."}