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
 /**
  * Send this HTTP request
  *
  * @throws Horde_Http_Exception
  * @return Horde_Http_Response_Base
  */
 public function send()
 {
     // at this time only the curl driver is supported
     $client = new \http\Client('curl');
     $body = new \http\Message\Body();
     $data = $this->data;
     if (is_array($data)) {
         $body->addForm($data);
     } else {
         $body->append($data);
     }
     $httpRequest = new \http\Client\Request($this->method, (string) $this->uri, $this->headers, $body);
     $client->setOptions($this->_httpOptions());
     $client->enqueue($httpRequest);
     try {
         $client->send();
         $httpResponse = $client->getResponse($httpRequest);
     } catch (\http\Exception $e) {
         throw new Horde_Http_Exception($e);
     }
     return new Horde_Http_Response_Peclhttp2((string) $this->uri, $httpResponse);
 }
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
 /**
  * Sends a request.
  *
  * @param string $path Request path
  * @param integer $method Request method
  * @param array $headers Array of headers
  * @return \http\Client\Response
  * @throws \Jyxo\Webdav\Exception On error
  */
 protected function sendRequest($path, $method, array $headers = array())
 {
     try {
         // Send request to a random server
         $request = $this->createRequest($this->getRandomServer(), $path, $method, $headers);
         $client = new \http\Client();
         $client->enqueue($request);
         $client->send();
         $response = $client->getResponse();
         if (null !== $this->logger) {
             $this->logger->log(sprintf("%s %d %s", $request->getRequestMethod(), $response->getResponseCode(), $request->getRequestUrl()));
         }
         return $response;
     } catch (\http\Exception $e) {
         throw new Exception($e->getMessage(), 0, $e);
     }
 }
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
    header('Content-Type: application/xml');
    $downstream_origin = getDownstreamOrigin();
    print <<<EOF
<?xml version="1.0" ?>
<cross-domain-policy>
  <site-control permitted-cross-domain-policies="master-only"/>
  <allow-access-from domain="{$downstream_origin}"/>
  <allow-http-request-headers-from domain="{$downstream_origin}" headers="*"/>
</cross-domain-policy>
EOF;
    exit;
}
$client = new http\Client();
$client->setOptions(['connecttimeout' => Conf::$proxy_http_request_connecttimeout, 'dns_cache_timeout' => Conf::$proxy_http_request_dns_cache_timeout, 'retrycount' => Conf::$proxy_http_request_retrycount, 'timeout' => Conf::$proxy_http_request_timeout]);
$client->enqueue($request)->send();
$response = new ProxyHttpResponse($client->getResponse(), $request);
$body = $response->getBody();
$headers = $response->getHeaders();
// Default - can be overriden below.
$headers['X-Frame-Options'] = 'SAMEORIGIN';
if (getDownstreamOrigin()) {
    $headers['Access-Control-Allow-Origin'] = getDownstreamOrigin();
    // See http://stackoverflow.com/questions/12409600/error-request-header-field-content-type-is-not-allowed-by-access-control-allow.
    $headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
    $headers['X-Frame-Options'] = 'ALLOW-FROM ' . getDownstreamOrigin();
}
header($response->getResponseInfo());
foreach ($headers as $key => $values) {
    // Don't overwrite security headers.
    if (isset($required_security_headers[$key])) {
        continue;
Exemplo n.º 7
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.º 8
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.º 9
0
 public function getTransactions($terminal)
 {
     assert(!is_null($terminal));
     assert(isset($terminal->url));
     assert($this->isLoggedIn());
     // Support merged terminal reports, where given an array of URLs instead of string:
     // Just use same method and merge results from all URLs
     if (is_array($terminal->url)) {
         $terminal_simple = clone $terminal;
         $transactions = array();
         foreach ($terminal->url as $url) {
             $terminal_simple->url = $url;
             $transactions += $this->getTransactions($terminal_simple);
         }
         return $transactions;
     }
     // Create HTTP request for single terminal URL ('terminal_simple')
     $request = new \http\Client\Request("GET", $terminal->url, 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));
     // 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 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);
     // Enumerate per-transaction info table rows
     $transactions = array();
     $rows = $xpath->query("//table//tr");
     for ($rowi = 0; $rowi < $rows->length; $rowi++) {
         $cols = $rows->item($rowi)->getElementsByTagName('td');
         if ($cols->length < 10) {
             continue;
         }
         // Normalize text values in cells
         for ($coli = 0; $coli < $cols->length; $coli++) {
             $cols->item($coli)->normalize();
         }
         // Check if this is header row or invalid row
         $shop = $cols->item(0)->nodeValue;
         $mid = $cols->item(1)->nodeValue;
         if (empty($shop) || !is_numeric($mid)) {
             continue;
         }
         // Get other transaction data
         $tid = $cols->item(2)->nodeValue;
         $date = new \DateTime($cols->item(3)->nodeValue);
         $currency = $cols->item(4)->nodeValue;
         $type = $cols->item(5)->nodeValue;
         $card_type = $cols->item(6)->nodeValue;
         $card_number = $cols->item(7)->nodeValue;
         $amount = floatval(str_replace(" ", "", $cols->item(8)->nodeValue));
         $auth_code = $cols->item(9)->nodeValue;
         // Push terminal data entry
         array_push($transactions, (object) array('terminal_id' => $tid, 'merchant_id' => $mid, 'date' => $date, 'currency' => $currency, 'type' => $type, 'amount' => $amount, 'card_type' => $card_type, 'card_number' => $card_number, 'auth_code' => $auth_code));
     }
     // Reset xml_error_mode
     libxml_use_internal_errors($xml_error_mode);
     return $transactions;
 }