Skip to content
Advertisement

Http failure response for https://localhost/***/api/get**.php?TOKEN=???: 0 Unknown Error

I’m working on a new app for my businnes and I need to convert my php web app to a mobile app.

I’m having issues while trying to get the json data from my php file which is :

    <?php
header("Access-Control-Allow-Credentials: true");
header("Content-Type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: *");

$api = true; // this is to bypass redirection to login screen

require(__DIR__ . '/../autoload.php');

if (isset($_GET['TOKEN']) && $_GET['TOKEN'] = '???') {

.... // Some code to get my values
    
    
    $res = array();
    .... // more code to get the values

    echo json_encode($res);
    
}else{
    die('Invalid token');
}

I’ve been testing httpclient in my ts file with https://jsonplaceholder.typicode.com/todos/1 and it was working. Here is my ts file:

    import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  orders: any[] = [];
  constructor(private http: HttpClient) {}

  ngOnInit() {
    this.getOrders().subscribe((value) => {
        for (let key in value) {
          console.log(value[key]);
          console.log(key);
          this.orders.push({
            shop: key,
            orders: value[key],
          });
        }
    });
  }

  getOrders() {
    console.log('function run 2');
    return this.http.get(
      'https://localhost/???/api/get???.php?TOKEN=???',
      {}
    );
  }
}

On the browser with ionic serve it works like a charm with my localhost api, but when I run ionic cordova run android --prod -l --consolelogs it only wroks with jsonplaceholder test api and not my localhost api

Do you think the issue is coming from the headers setting of my php file, my get request or even my wamp localhost where the php file is store ?

Edit

My ssl certificate seems to not be valid, but I’ve tested the same api of jsonplaceholder and it was working with http, I’ve already tried to put my php file on a server that is running with a valid ssl certificate and it wasn’t working too, that’s why I’m quiet lost

Advertisement

Answer

After long research I’ve find a way to fix this (at least bypass):

I’ve just used my run or serve function with –external and called my php file with my public ip used to serve my project (same as my localhost ip where my php file is store).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement