zoukankan      html  css  js  c++  java
  • kepware http接口 php

    读取某变量的值(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 httpClient;
    $request = new httpClientRequest;
    
    $request->setRequestUrl('http://127.0.0.1:39321/iotgateway/read');
    $request->setRequestMethod('GET');
    $request->setQuery(new httpQueryString(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;
    }
  • 相关阅读:
    MyBatis的Mapper接口以及Example的实例函数及详解
    数据存储
    广播
    java线程复习3(线程的中断)
    java线程复习2(获取和设置线程信息)
    java线程复习1(线程创建)
    最好的启动方式
    工厂模式
    欧几里得算法
    组合数打表
  • 原文地址:https://www.cnblogs.com/dXIOT/p/10626704.html
Copyright © 2011-2022 走看看