我正在尝试使用PHP Unirest请求REST API。 打印的错误如下:
URL错误,冒号是第一个字符
我的代码:
<?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";
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;
}
}
“ isset($ _ POST ['primeiro']”是当我单击HTML中的按钮时,它在PHP中调用该函数。 我真的不知道该怎么用...
答案 0 :(得分:0)
您需要添加https://
之类的协议。
在协议之前,还有其他人也遇到了同样的问题... https://github.com/Azure/doAzureParallel/issues/44
URL不是http:localhost:8080/public
还请检查您的$_POST
变量中是否没有恶意输入,也许您需要在包含适当字符的字段上使用urlencode()
。