Hosting and favicon error 404

Asked

Viewed 87 times

0

I have an API developed with Slim 3. The API worked perfectly, testing with Postman or by browser, everything worked perfectly.

I had to change the hosting. So I went up the API to new host and tested it via browser and it worked. When I tested it by Postman it returned me the error:

This site requires Javascript to work, Please enable Javascript in your browser or use a browser with Javascript support

I went back to the browser and tried the request again, only this time with the console open. I noticed that along with the request to the web service is going a request to favicon.ico and as the file does not exist on the host it returns a 404 error along with an error page.

In the browser it works, however, when testing via Postman it returns me the error mentioned above, what did not happen in the old hosting.

This is the API code:

$app = new app($container,[
    'settings' => [
        'displayErrorDetails' => true
    ]
]);

$app->group('/venda', function () use ($app) {
        $app->get('', function (Request $request, Response $response, array $args) {
                return 'teste';
        });  
});

$app->run();

And since I haven’t passed the domain to the new hosting, I use this link to access the API:

http://apiparsoni.rf.gd/v1/venda

Is there any way to show the browser that this is an API and prevent it from making that request?

  • The fact that the favicon does not exist does not seem to be related to the answer you got in Postman since it does not request the favicon. What is the code of the resource you are requesting and how you requested it?

  • @Phpatrick When editing a question, be careful not to add acronyms and proper names as code snippets.

  • I made an edit on the question and includes more information of the resource code and the link that makes the request.

  • @Andersoncarloswoss But everything that is related to function names, Apis or the code itself fits within the ``, or not?

  • 1

    @Phpatrick Function name yes; acronyms in general and proper names are part of the text and do not require special formatting.

  • @Andersoncarloswoss I got beauty

Show 1 more comment

2 answers

1

Giving a search I found this Issue on Postman’s Github where it is mentioned that this error comes from your hosting server, usually originated on free hosting servers, where they disable the use of Javascript for API calls allowing only by calls made by browsers.

And it seems to me you’re staying at Infinityfree which is just the hosting service quoted on Issue.

Check that the server you are hosting has some configuration to enable this feature, otherwise you will have to find another alternative.

I tried to make the request for other online API testing services and everyone gets the same error, confirming that this is probably the problem really.

If you would like to test follow 2 examples:

Reqbin

Apitester

  • That’s pretty much it. Whenever a request is made on this hosting an internal page of them is executed that checks some parameters of the request with JS. If everything is ok, the user is moved to the page correctly. In Postman there is no running engine for JS, so the error is displayed.

1

This is a particularity of the hosting you are using.

Every time someone makes a request on this server the existence of the cookie is checked __test - and possibly validated the value of it (we can’t be sure). When the cookie does not exist (or invalid) the user is (internally) directed to a page of the hosting itself. There is no real redirect, only instead of the request reaching your application it is processed by the server, returning an HTML page with a JS code:

<html>
    <body>
        <script type="text/javascript" src="/aes.js" ></script>
        <script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f
            <d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("e783838a5007920e7955c7e2bd420274");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://apiparsoni.rf.gd/v1/venda?i=1";
            </script>
            <noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript>
        </body>
    </html>

Which will basically define the value of the cookie __test and will move the user to a new URL with a parameter i in query string (possibly to avoid caching the page itself). In this new request, as the cookie will exist and will be valid, the request will arrive to your application and you will have the expected response.

inserir a descrição da imagem aqui

Since Postman does not have an internal Javascript engine, the Javascript code of the page will not be executed and therefore the cookie is not created and is not moved to the page of your application. Including how they used the tag <noscript>, is she who is rendered presenting the error described in the question.

If you set the cookie value manually with a valid value the request will work normally in Postman:

inserir a descrição da imagem aqui

I just can’t say how long this cookie will remain valid. If you consider that it defines the validity as expires=Thu, 31-Dec-37, probably you can use the same value without worrying.

  • Perfect. That’s exactly it.. I switched hosts and everything worked perfectly. Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.