Laravel MethodNotAllowedHttpException if request has base64 image data - laravel

I've a problem when I'm sending HTTP request containing base64 image data it throws " MethodNotAllowedHttpException ", but if the request doesn't contain a base64 data it works fine.
PS: the same request works on my localhost, but not working on my shared web hosting.
example of the request :
https://prnt.sc/jjybgw

It's problem of the post request method.
when you send the get request and route define of post request. Than occurred this issue
First check your form request URL
And also check in web.php
Route::get()
Or
Route::post()

Related

Laravel PUT Request fails : Parse Error: The response has a duplicate "Content-Length" header

Context
Using Postman I send a PUT HTTP request to my Laravel API.
Expected behavor
Postman should show "test" as a response.
Actual behavior
Postman shows the error "Parse Error: The response has a duplicate "Content-Length" header" as a response.
The route
I have defined in api.php the following route:
Route::put('/test', function(Request $request) {
return 'test';
})->name('test');
This route exists: indeed, php artisan route:list returns the following...
PUT | api/test | test | Closure | api
The request
In Postman I have defined the following request (the URL is in the shape of: https://<laravel site>/api/test):
What I've tried to do
According to the Laravel docs, _method = PUT should be sent when a HTML form pointing to a PUT route is sent with POST because it's incompatible with PUT. Normally here, since I use JSON, it's not the case. But even though it could be useless, I've put it, in case I was wrong.
Moreover I've explicitly specified application/json as value for Content-Type and Accept. Also I've specified XMLHttpRequest for make the server know it's an XHRequest.
Finally, there is the CSRF token and the Sanctum token (Bearer Token). I don't know if their values are correct but thanks to other requests not shown here, I know I'm authenticated using Fortify so normally the Sanctum token value may not be used (because of the standard authentication cookie session is defined by Fortify) ; for the CSRF token maybe it's the same.
Question
Why doesn't Laravel simply show "test"?
Clues
NGinx configuration could be the root cause of this problem. Digging deeper...
Just because I can't see the url. Do you have '/api/test'?

How does postman app set request body for a GET request

When I was trying in browser to send a GET request with data from bootstrap datatable ajax to a C# MVC controller method, not all the data that was send was mapped to the model object. Some properties in the model object still remained with null/default value.
I verified the property names and no issues in that. But when I did the same thing in postman app the data was successfully bound to the model object.
Two things that I noted in the postman app is that:
The request data is not send in the query string parameter rather in
the request body with still the method type as GET (I don't know
how that is possible), but in browser as usual the data was URL
encoded and was sent as query string parameter.
In post man app the request headers also contains "Content-Type"
header with "application/json" as value.
So I also tried with "Content-Type" header with "application/json" but still no use the data was not bound.
Finally I chose the common way, I just set the "Content-Type" header with "application/json", stringified the data with JSON.stringify and I set the type as "POST" and it successfully got mapped.
What I got struggling is, how does the postman app alone can send a GET request like that with data in the request body.
If anyone has idea about this please tell me that would help me to have an idea about the HTTP requests.
1.) PostMan - GET Request Format
2.) PostMan - Get Request Network Data
3.) PostMan - Get Request Network Data - Raw Format
4.) Backend - Contoller Received Data
1.) Browser - GET Request Format
2.) Browser - Query String Parameters
3.) Backend - Contoller Received Data

Update a Google Sheet Using HTTP Request in Postman

I have a server needing to update a shared Google Sheet. It generates special tokens for offline use so doesn't work with PHP quickstart module.
I am trying to setup request in Postman for this action:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update
But get the following result:
Is it possible to use HTTP for this API?
Turns out I had to add ?valueInputOption=RAW on the end of my URL request and removed valueInputOption from the request body JSON.
The valueInputOption should be passed as params to the POST URL, it should not be in the request body.
Also the sheetID and the range should be sent in the URL.
I suppose it should be a POST call not PUT.

Laravel 5.3 Returns 302 with Request Validation - Ajax Request

I am having trouble with an ajax request to a Laravel application, specifically making a POST request to an authentication controller. I'm sending a post request with SuperAgent to a controller that uses a Request class to validate the input. The request carries a password and a username. When I inspect the console I'm getting back a GET 200 OK and a POST 302 Not Found. I tried debugging the application routes but nothing seemed to work.
Turns out it was something very simple. Having used jquery for a long time to make ajax request, I overlooked a very important header. The 'Accept', 'application/json' Header. Debugging the Request validation, I noticed that Laravel's expectsJson method was returning false, so all I had to do was add said header to the SuperAgent request object.

laravel validation during ajax request

Please somebody explain this info from Laravel docs "When using the validate method during an AJAX request, Laravel will not generate a redirect response. Instead, Laravel generates a JSON response containing all of the validation errors. This JSON response will be sent with a 422 HTTP status code."
What does "during an AJAX request" exactly mean here?
If I'm set like this:
User submits input from a form in the view.
The route calls the method for post in the controller
The request is validated in the controller
case 1) Request passes validation and input is stored in the DB -> Response is returned as JSON for a script that updates the view on the fly.
case 2) Request doesn't pass validation, what is returned here? I think a redirect and if not how can you check if validation has failed to return a JSON instead?
And is this scenario similar to what the docs talk about? If not then what?
The response to an AJAX call in this case is a JSON string
Case 1: as you said
Case 2: A JSON String with the error messages. Look into your Chrome dev tools into the Network tab, there you'll see the exact responses.
When handling a validation failure, laravel automatically generates an error response. Normally this will redirect the user back to their form, but in the case of an AJAX request it will instead return a JSON response with the details of what failed validation.
Laravel relies on the symfony request object to detect AJAX requests, specifically this line:
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
If you are encountering issues with your requests not being treated as AJAX, make sure your client is properly setting the X-Requested-With header

Resources