kepware http接口 php

时间:2024-11-07 17:05:26

读取某变量的值(HttpRequest

<?php

$request = new HttpRequest();
$request->setUrl('http://127.0.0.1:39321/iotgateway/read');
$request->setMethod(HTTP_METH_GET); $request->setQueryData(array(
'ids' => array(
'Channel1.Device1.tag1',
'Channel1.Device1.tag2'
)
)); $request->setHeaders(array(
'cache-control' => 'no-cache',
'Accept-Language' => 'zh-CN,zh;q=0.9',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
'Upgrade-Insecure-Requests' => '1',
'Cache-Control' => 'max-age=0',
'Connection' => 'keep-alive'
)); try {
$response = $request->send(); echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}

读取某变量的值(pecl_http

<?php

$client = new http\Client;
$request = new http\Client\Request; $request->setRequestUrl('http://127.0.0.1:39321/iotgateway/read');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString(array(
'ids' => array(
'Channel1.Device1.tag1',
'Channel1.Device1.tag2'
)
))); $request->setHeaders(array(
'cache-control' => 'no-cache',
'Accept-Language' => 'zh-CN,zh;q=0.9',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
'Upgrade-Insecure-Requests' => '1',
'Cache-Control' => 'max-age=0',
'Connection' => 'keep-alive'
)); $client->enqueue($request)->send();
$response = $client->getResponse(); echo $response->getBody();

读取某变量的值(curl

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_PORT => "39321",
CURLOPT_URL => "http://127.0.0.1:39321/iotgateway/read?ids=Channel1.Device1.tag1,Channel1.Device1.tag2",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: zh-CN,zh;q=0.9",
"Cache-Control: max-age=0",
"Connection: keep-alive",
"Upgrade-Insecure-Requests: 1",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
"cache-control: no-cache"
),
)); $response = curl_exec($curl);
$err = curl_error($curl); curl_close($curl); if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}