Error making the request

Asked

Viewed 39 times

0

I am trying to place a request in a REST API using PHP Unirest. The error that appears when I print is:

Bad URL, Colon is first Character

The mistake:

PHP Fatal error: Uncaught Unirest Exception: Bad URL

My code:

<?php
require __DIR__ . '/../vendor/autoload.php';

use Unirest\Request as UniRequest;
use CurlFile;

if (isset($_POST['primeiro'])) {
    $where = $_POST["where"];
    $equal = $_POST["equal"];

    $resultado = new pedidos;
    $valores = $resultado->LogIgualA($where, $equal);
}

class pedidos {
    function LogIgualA($where, $equal) {
        $wsURL = "localhost:8080/public";
        $headers = array('Accept' => 'application/json');

        try {
            $valores = UniRequest::get($wsURL."/visual/json_log/where=".$where."/equal=".$equal, $headers, null);
        } catch (Exception $e) {
            echo $e->getMessage();
        }

        $valoresAux = $valores->body;

        $valores = [];

        foreach($valoresAux as $z){
            $ID = $z->ID;
            $DateConnection = $z->DateConnection;
            $TimeToServe = $z->TimeToServe;
            $ClientIP = $z->ClientIP;
            $CacheCode = $z->CacheCode;
            $Bytes = $z->Bytes;
            $Method = $z->Method;
            $RequestProtocol = $z->RequestProtocol;
            $RequestIP = $z->RequestIP;
            $RequestPort = $z->RequestPort;
            $RequestFolder = $z->RequestFolder;
            $Auth = $z->Auth;
            $RouteLeft = $z->RouteLeft;
            $RouteRight = $z->RouteRight;
            $ContentType = $z->ContentType;
        }

        return $valores;
    }
}

The "isset($_POST['first'])" is when I click the butao in HTML it calls the function within PHP. If you put the variable $wsURL com "http://localhost:8080/public" just keep charging endlessly.

  • First: I think the right thing to do is to use it with http:// anyway, we just need to find what makes it load endlessly. According to: In foreach I see that you are saving the values in variables but then do not pass it back to $values and always returns an empty value. Third: I don’t know what this might cause, but you’re passing the $headers to the function but don’t set that variable before in the code (at least not in the code posted here)

  • I already updated my code, and what is after the foreach I haven’t finished, it was just to test. I’ve already been looking for what you might be doing with http:// is loading endlessly but I can’t find any information either.

No answers

Browser other questions tagged

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