Exemplo n.º 1
0
 public function command($cmd)
 {
     $request = new http\Client\Request("GET", $this->JobSchedulerBaseURL . ":" . $this->JobSchedulerPort . "/" . $cmd, ["User-Agent" => "My Client/0.1"]);
     $request->setOptions(["timeout" => 60]);
     $client = new http\Client();
     $client->enqueue($request)->send();
     // pop the last retrieved response
     $response = $client->getResponse();
     $this->answer = simplexml_load_string($response->getBody());
     $this->http_response_status = ["code" => $response->getResponseCode(), "info" => $response->getInfo()];
     $this->answer_error = $this->answer->answer[0]->ERROR[0];
 }
Exemplo n.º 2
0
 /**
  * @param string[] $headers
  * @param string $body
  * @return bool Success
  */
 public function send($headers, $body)
 {
     if (!is_array($headers)) {
         $headers = [$headers];
     }
     $body = strval($body);
     unset($headers['Host']);
     // client will generate "Host" header
     $request = new http\Client\Request('POST', $this->getEndpointUrl(), $headers, (new http\Message())->getBody()->append($body));
     $timeoutSeconds = $this->getTimeoutSeconds();
     if ($timeoutSeconds != null) {
         $request->setOptions(['timeout' => $timeoutSeconds]);
     }
     $response = (new http\Client())->enqueue($request)->send()->getResponse($request);
     $this->_lastNativeResultFromSend = $response;
     $responseHttpCode = $response->getResponseCode();
     // Any HTTP response code in the 200s is considered success
     $this->_lastSuccessFromSend = $responseHttpCode >= 200 && $responseHttpCode <= 299;
     return $this->_lastSuccessFromSend;
 }
Exemplo n.º 3
0
 public function sendRequest($url, array $query_data = [], $cookie = true)
 {
     /**
      * @var \HttpQueryString $params
      */
     $queryData = new \http\QueryString($query_data);
     /**
      * @var \HttpRequest $http
      */
     $request = new \http\Client\Request("GET", $url);
     if (!empty($queryData)) {
         $request->getBody()->append($queryData);
     }
     $request->setContentType("application/x-www-form-urlencoded");
     $client = new \http\Client();
     $cookie_file = 'cookie.log';
     if ($cookie) {
         $cookie_str = file_exists($cookie_file) ? file_get_contents($cookie_file) : '';
         $cookie = new Cookie($cookie_str);
         $client_cookie = $cookie->getCookie('frontend');
         if ($client_cookie != 'deleted') {
             $client->addCookies(['frontend' => $client_cookie]);
         }
     }
     $client->enqueue($request);
     $client->send();
     /** @var \HttpResponse $response */
     $response = $client->getResponse($request);
     printf("Sent:\n%s\n\n", $response->getParentMessage());
     printf("%s returned '%s'\n%s\n", $response->getTransferInfo("effective_url"), $response->getInfo(), $response->getBody());
     file_put_contents($cookie_file, '');
     foreach ($response->getCookies() as $cookie) {
         /* @var $cookie http\Cookie */
         foreach ($cookie->getCookies() as $name => $value) {
             $cookie = new \http\Cookie();
             $cookie->addCookie($name, $value);
             file_put_contents($cookie_file, $cookie->toString(), FILE_APPEND);
         }
     }
     print_r($response->getHeaders());
     return json_decode($response->getBody(), true);
 }
Exemplo n.º 4
0
 /**
  * Creates a request.
  *
  * @param string $server Server
  * @param string $path Path
  * @param integer $method Request method
  * @param array $headers Array of headers
  * @return \http\Client\Request
  */
 protected function createRequest($server, $path, $method, array $headers = array())
 {
     $request = new \http\Client\Request($method, $server . $path);
     $request->setOptions($this->curlOptions);
     $request->setSslOptions($this->curlSslOptions);
     $request->setHeaders($headers + array('Expect' => ''));
     return $request;
 }
Exemplo n.º 5
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('GET');
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Exemplo n.º 6
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}');
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array('content-type' => 'application/json'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Exemplo n.º 7
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('GET');
$request->setHeaders(array('x-foo' => 'Bar', 'accept' => 'application/json'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Exemplo n.º 8
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->addForm(NULL, array(array('name' => 'foo', 'type' => 'text/plain', 'file' => 'hello.txt', 'data' => 'Hello World')));
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Exemplo n.º 9
0
 function posts_where($where)
 {
     // if I leave the is_search I get the normal search added (OR)
     if (is_search()) {
         $s = $_GET['s'];
         if (!empty($s)) {
             $request = new http\Client\Request("GET", "http://localhost:3058/scriptjs/query?q=" . $s, ["User-Agent" => "My Client/0.1"]);
             $request->setOptions(["timeout" => 1]);
             $client = new http\Client();
             $client->enqueue($request)->send();
             // pop the last retrieved response
             $response = $client->getResponse();
             $list = $response->getBody();
             if ($s != "empty") {
                 if ($s != "none") {
                     global $wpdb;
                     $where = str_replace('(' . $wpdb->posts . '.post_title LIKE', '(' . $wpdb->posts . '.ID in (' . $list . ')) OR (' . $wpdb->posts . '.post_title LIKE', $where);
                     $where = ' and (' . $wpdb->posts . '.ID in (' . $list . '))';
                     // SELECT SQL_CALC_FOUND_ROWS  ptbopq6_posts.ID FROM ptbopq6_posts  WHERE 1=1 (ptbopq6_posts.ID in (4365,4401))  ORDER BY ptbopq6_posts.post_title LIKE '%xapi%' DESC, ptbopq6_posts.post_date DESC LIMIT 0, 5 made by require('C:\inetpub\kneaver.com\wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts
                     // made by parse-search(q) called by get_posts() all in query.php
                 }
             }
         }
     }
     return $where;
 }
Exemplo n.º 10
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString(array('foo' => array('bar', 'baz'), 'baz' => 'abc', 'key' => 'value')));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Exemplo n.º 11
0
<?php

/*
 * 在当前目录设置 http 服务器
 * 如:php -S 0.0.0.0:3333
 */
error_reporting(E_ALL);
session_name('libo');
session_save_path('/tmp/sess');
session_start();
$_SESSION['file'] = __FILE__;
session_write_close();
$request = new http\Client\Request('GET', 'http://172.16.100.110:3333/serv.php?id=' . session_id(), ['User-Agent' => 'My Client/1.0', 'Cookie' => session_name() . '=' . session_id()]);
$request->setOptions(['connecttimeout' => 1, 'timeout' => 3]);
$client = new http\Client();
$client->enqueue($request)->send();
$response = $client->getResponse($request);
echo "[Request]\n";
print_r($request->getHeaders());
echo "\n";
print_r($request->getRequestUrl());
echo "\n";
echo "\n[Response]\n";
print_r($response->getHeaders());
echo "\n";
echo $response->getBody()->toString();
Exemplo n.º 12
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(new http\QueryString(array('foo' => 'bar')));
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setQuery(new http\QueryString(array('foo' => array('bar', 'baz'), 'baz' => 'abc', 'key' => 'value')));
$request->setHeaders(array('content-type' => 'application/x-www-form-urlencoded', 'accept' => 'application/json'));
$client->setCookies(array('bar' => 'baz', 'foo' => 'bar'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Exemplo n.º 13
0
 public function getPaymentReports($date_from, $date_to)
 {
     // Create HTTP request
     $request = new \http\Client\Request("GET", UCS::URL_REPORTS, array('User-Agent' => UCS::USER_AGENT, 'Accept' => UCS::ACCEPT, 'Accept-Language' => UCS::ACCEPT_LANGUAGE, 'Host' => UCS::HOST, 'Cookie' => $this->getCookieHeader(), 'Referer' => UCS::URL_REPORTS, 'Upgrade-Insecure-Requests' => 1));
     $request->setQuery(array('show' => 1, 'start' => $date_from->format('Y-m-d'), 'end' => $date_to->format('Y-m-d'), 'submit.x' => 6, 'submit.y' => 15, 'dates' => 'proc', 'type' => 'detail', 'page' => 1));
     // Create HTTP client with appropriate TLS version
     $client = new \http\Client();
     $client->setOptions(array("ssl" => ["version" => \http\Client\Curl\SSL_VERSION_TLSv1]));
     // Do the Http request
     $client->enqueue($request)->send();
     // Get Response cookies and text
     $re = $client->getResponse($request);
     $html = $re->getBody();
     // Suppress HTML parser warnings
     $xml_error_mode = libxml_use_internal_errors(true);
     // Parse HTML into DOM/XPATH objects
     $dom = new \DomDocument();
     $dom->loadHTML($html);
     $xpath = new \DomXPath($dom);
     // Load daily reports table and construct informational objects
     $reports = array();
     $rows = $xpath->query("//table[2]//tr[1]/td[3]/table[2]//tr");
     for ($rowi = 1; $rowi < $rows->length; $rowi++) {
         $row = $rows->item($rowi);
         $cols = $row->getElementsByTagName('td');
         if ($cols->length < 8) {
             continue;
         }
         // Construct instance from row data
         $report = new UCSReport($this, $cols, $xpath);
         array_push($reports, $report);
     }
     // Reset xml_error_mode
     libxml_use_internal_errors($xml_error_mode);
     return $reports;
 }