I'm trying to send post request data
to my api
.
The api
works fine in my postman,
But in my laravel project, I'm getting the caution
like this
Provisional headers are shown
API to Send Post Request Data
url: https://api.mydomain.com/api/login
{ "companyID":"2018-101", "password":"123456" }
Content-Type : application/json
Accept : application/json
In my Laravel project here's my ajax
that performs the sending of post
data to the api
.
$.ajax({
headers:{'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
url: "https://api.mydomain.com/api/login",
method: "POST",
data:{
companyID:"2018-101",
password:"123456"
},
dataType: "json",
success:function(data)
{
alert("Successfully Login!");
},
error: function(xhr, ajaxOptions, thrownError){
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
Here's my Cors.php
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
/**
* Handle an incoming request.
*a
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers',' Origin, Content-Type, Accept, Authorization, X-Request-With')
->header('Access-Control-Allow-Credentials',' true');
}
}
My Kernel.php
\App\Http\Middleware\Cors::class,
UPDATED
Tried to change the
data:{
companyID:"2018-101",
password:"123456"
},
to
data: JSON.stringify({ "companyID": "2018-101", "password" : "123456" }),
contentType: "application/json",