Closed diogo-vf closed 5 days ago
@diogo-vf are you sure above code works for you ? i had to make few changes to run it locally. I don't see any spaces.
Route::any('exports/{channel}/{type?}', function ($channel, $type = null) {
$content = <<<XML
<?xml version="1.0"?>
<catalog>
<!-- Your XML content goes here -->
</catalog>
XML;
return response($content, 200)
->header('Content-Type', 'application/xml');
})->name('exports');
@vjaykoogu Hi,
I have 'auth:sactum' middleware at the top level of my api.php
, but the rest is the same.
Route::middleware(['auth:sanctum'])
->group(function () {
Route::any('exports/{channel}/{type?}', `myCallback` )->name('exports');
Route::post( [...] );
[...]
});
@diogo-vf could you please try in different browser?, This is what i see on my machine.
that's my case
Removing the Content-Type works:
@diogo-vf Forgot to add Safari Result, I dint make any changes i can see the same on safari too. (my previous screenshot is from Brave browser)
I use Firefox as my main browser
But i can't understand why in your case, you don't have 4spaces when calling the "export"
I tried with chrome and have also the 4 spaces problem.
I've also comment all my routes in my api.php
and move
Route::any('exports/{channel}/{type?}', function ($channel, $type = null) {
$content = <<<XML
<?xml version="1.0"?>
<catalog>
<!-- Your XML content goes here -->
</catalog>
XML;
return response($content, 200)
->header('Content-Type', 'application/xml');
})->name('exports');
to first line and same result, always 4 spaces 🫤at the beginning of the xml result
Laravel Version
11.0 and 11.25
PHP Version
8.2.22
Database Driver & Version
No response
Description
After calling my custom api route and asking an xml response, it return every time at the first line 4 spaces following by a
\n
.During my tests, I use the followin XML: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)
the code in the API route file:
The answer:
But when I remove the header
Content-Type
, the first line is correctly<?xml version="1.0"?>
, but the Content-Type is text/html; charset=UTF-8.Steps To Reproduce
Add the following route in the
routes/api.php
file:Call
backend.laravel.vm/api/exports/demo
and you're result should be: