Getting Excepting while using Api Laravel 8 API have 3 parameters
1: contact_no
2: message
3:client_id
When i try to send data in html and script format in message parameters like this
<a>Hi</a><script></script>
it through exception like this
Error: The GET method is not supported for this route. Supported methods: POST.
this issue only appears on the online server. In localhost its working fine
api.php code :
Route::post('/receive-customer-messages', [App\Http\Controllers\Api\CustomerMessageController::class, 'receive_customer_message']);
@ha77an Read your error message. You’re sending a GET request to an endpoint that’s expecting a POST.
How are you sending the data? You didn't show the code.
when I try to send
message = "<a>Hi</a><script></script>"
exceptional will appear otherwise API working fine
public function receive_customer_message(Request $request)
{
$rules= [
'contact' => 'required',
'client_id' => 'required',
'message' => 'required',
];
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
$response['status'] = 'empty';
$response['message'] = $validator->errors()->first();
return response()->json($response);
}
// after validation i save the data into db
}
@ha77an Again, you’re not showing the code on how you make the request. Until you do, no one can help.
Actually, I'm building an email portal
in this API I fetch the emails and message from the specific email account and save into database.
I found the solution.
I will encode message data while sending to API and then decode it to save it into the database.
Please sign in or create an account to participate in this conversation.