php - Http failure response for (unknown url): 0 Unknown Error

953

I'm currently developing a service-based system and having some problems with the http requests(seems to be a problem with CORS - Cross origin resource sharing).

The API where I'm sending the request is written in PHP, with the Slim framework and I'm actually enabling CROS with the following code:

$app->add(function ($req, $res, $next) {
    $response = $next($req, $res);
    return $response
            ->withHeader('Access-Control-Allow-Origin', '')
            ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
            ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
});

But when I send requests from the front-end(written with Angular):

this.http.get(this.base_url + "api/users/")
    .subscribe(
        (data) => {
            console.log(data);
        },
        (error) => {
            console.log(error);
    });

I get the following error:

name:"HttpErrorResponse"

message:"Http failure response for (unknown url): 0 Unknown Error"

The two projects are running in Docker, if that's adds an information.

Does anyone has any idea where the problem could be?

Thank you in advance!

153

Answer

Solution:

it is usually 500 code internal server error for this case.

Similar causes:

1. Server (API) not running or disconnected
2. Your api code has problem
3. You specify wrong url

People are also looking for solutions to the problem: php - Automatic git pull to server: Host key verification failed

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.