コード例 #1
0
 function post($url, $fields = array(), $http_options = array())
 {
     $http_options = array_merge($this->http_options, $http_options);
     $res = is_array($fields) ? http_post_fields($url, $fields, array(), $http_options, $this->response_info) : http_post_data($url, $fields, $http_options, $this->response_info);
     $this->http_parse_message($res);
     return $this->response_object->body;
 }
コード例 #2
0
function get_trusted_ticket($wgserver, $user, $remote_addr)
{
    $params = array('username' => $user, 'client_ip' => $remote_addr);
    $server = PROTOCOL . "://{$wgserver}/trusted";
    $resp = http_parse_message(http_post_fields($server, $params))->body;
    //testing
    // print '<script type="text/javascript">alert("My addy ' . $_SERVER['SERVER_ADDR'] . ' is getting response from server ' . $server . ' for user ' . $user . ' of ' . print_r($resp) . '");</script>';
    //print_r ($resp);
    //actually return it
    return $resp;
}
コード例 #3
0
 function do_post_request($url, $data, $optional_headers = null)
 {
     /***
      * Do a POST request
      *
      * @param string $url the destination URL
      * @param array $data The paramter as key/value pairs
      * @return response object
      ***/
     $bareUrl = $url;
     $url = urlencode($url);
     $params = array('http' => array('method' => 'POST', 'content' => http_build_query($data), 'header' => 'Content-type: application/x-www-form-urlencoded'));
     if ($optional_headers !== null) {
         $params['http']['header'] = $optional_headers;
     }
     $ctx = stream_context_create($params);
     # If url handlers are set,t his whole next part can be file_get_contents($url,false,$ctx)
     try {
         ini_set("default_socket_timeout", 3);
         $response = file_get_contents($bareUrl, false, $ctx);
         if (empty($response) || $response === false) {
             throw new Exception("No Response from file_get_contents");
         }
     } catch (Exception $e) {
         ini_set("allow_url_fopen", true);
         $fp = @fopen($bareUrl, 'rb', false, $ctx);
         if (!$fp) {
             if (function_exists("http_post_fields")) {
                 $response = http_post_fields($bareUrl, $data);
                 if ($response === false || empty($response)) {
                     throw new Exception("Could not POST to {$bareUrl}");
                 }
                 return $response;
             } else {
                 if (function_exists("curl_init")) {
                     # Last-ditch: CURL
                     $ch = curl_init($bareUrl);
                     curl_setopt($ch, CURLOPT_POST, 1);
                     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
                     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                     curl_setopt($ch, CURLOPT_HEADER, 0);
                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                     $response = curl_exec($ch);
                     if ($response === false || empty($response)) {
                         throw new Exception("CURL failure: " . curl_error($ch));
                     }
                     return $response;
                 } else {
                     throw new Exception("Problem POSTing to  {$bareUrl}");
                 }
             }
         }
         $response = @stream_get_contents($fp);
         if ($response === false) {
             throw new Exception("Problem reading data from {$bareUrl}");
         }
     }
     return $response;
 }
コード例 #4
0
ファイル: OAuth.php プロジェクト: redspade-/plurkoauth
    function request($uri, $method="GET", $headers=null, $body='') {

	if (!isset($headers))
	    $headers = array();

	if ($method == "POST") {
	    if (!isset($header['Content-Type']))
		$headers['Content-Type'] = self::DEFAULT_POST_CONTENT_TYPE;
	}
	$is_form_encoded = (isset($headers) and
	    $headers['Content-Type'] == self::DEFAULT_POST_CONTENT_TYPE);

	$parameters = null;

	if ($is_form_encoded and isset($body))
	    parse_str($body,$parameters);

	$req = Request::from_consumer_and_token($this->consumer,
		$this->token, $method, $uri,
		$parameters, $body, $is_form_encoded);
	$req->sign_request($this->method, $this->consumer, $this->token);
	$headers = array_merge($headers, $req->to_header());

	$parsed = parse_url($uri);
	$realm = http_build_url(
	    array(
		"scheme" => $parsed['scheme'],
		"host"   => $parsed['host'],
		)
	    );

	if ($is_form_encoded) {
	    return http_parse_message(
		http_post_fields($uri, $parameters, null, array(headers => $headers))
	    )->body;
	} elseif ($method == "GET")  {
	    $uri = $req->to_url();
	    return http_get($uri, array(headers => $headers));
	} else {
	    $headers = $req->to_header($realm);
	    return http_head($uri, array(headers => $headers));
	}

	return http_request($method, $uri, $body, array(headers => $headers));
    }
コード例 #5
0
ファイル: tiki-tests_replay.php プロジェクト: rjsmelo/tiki
/**
 * @param $url
 * @param bool $use_tidy
 * @return array
 */
function verif_url($url, $use_tidy = TRUE)
{
    global $cookies;
    static $purifier;
    static $loaded = false;
    $smarty = TikiLib::lib('smarty');
    $result = array();
    $get = get_from_dom($url->getElementsByTagName('get')->item(0));
    $post = get_from_dom($url->getElementsByTagName('post')->item(0));
    $xpath = $url->getElementsByTagName('xpath')->item(0)->textContent;
    $data = $url->getElementsByTagName('data')->item(0)->textContent;
    $urlstr = $url->getAttribute('src');
    if (extension_loaded('http')) {
        $options['timeout'] = 2;
        $options['connecttimeout'] = 2;
        $options['url'] = $url->getAttribute('src');
        $options['referer'] = $url->getAttribute('referer');
        $options['redirect'] = 0;
        $options['cookies'] = $cookies;
        $options['cookiestore'] = tempnam('/tmp/', 'tiki-tests');
        // Close the session to avoid timeout
        session_write_close();
        switch (strtolower($url->getAttribute('method'))) {
            case 'get':
                $buffer = http_get($urlstr, $options, $info);
                break;
            case 'post':
                $buffer = http_post_fields($urlstr, $post, NULL, $options, $info);
        }
        $headers = http_parse_headers($buffer);
        if (isset($headers['Set-Cookie'])) {
            foreach ($headers['Set-Cookie'] as $c) {
                TikiLib::parse_str($c, $cookies);
            }
        }
        $buffer = http_parse_message($buffer)->body;
    } elseif (extension_loaded('curl')) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $urlstr);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
        curl_setopt($curl, CURLOPT_TIMEOUT, 2);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_REFERER, $url->getAttribute('referer'));
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($curl, CURLOPT_USERAGENT, 'TikiTest');
        // We deal with the cookies
        $cookies_string = '';
        foreach ($cookies as $c => $v) {
            $cookies_string .= "{$c}={$v}; path=/;";
        }
        curl_setopt($curl, CURLOPT_COOKIE, $cookies_string);
        switch (strtolower($url->getAttribute('method'))) {
            case 'get':
                curl_setopt($curl, CURLOPT_HTTPGET, true);
                break;
            case 'post':
                curl_setopt($curl, CURLOPT_POST, true);
                $post_string = '';
                foreach ($post as $p => $v) {
                    if ($post_string != '') {
                        $post_string .= '&';
                    }
                    $post_string .= "{$p}={$v}";
                }
                curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);
        }
        // Close the session to avoid timeout
        session_write_close();
        $http_response = curl_exec($curl);
        $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $header = substr($http_response, 0, $header_size);
        $body = substr($http_response, $header_size);
        preg_match_all('|Set-Cookie: (.*);|U', $header, $cookies_array);
        foreach ($cookies_array[1] as $c) {
            $cookies_tmp .= "&{$c}";
        }
        TikiLib::parse_str($cookies_tmp, $cookies_titi);
        if (!is_array($cookies)) {
            $cookies = array();
        }
        $cookies = array_merge($cookies, $cookies_titi);
        $buffer = $body;
        curl_close($curl);
    }
    if (extension_loaded('tidy')) {
        $data = tidy_parse_string($data, array(), 'utf8');
        $buffer = tidy_parse_string($buffer, array(), 'utf8');
        if ($use_tidy) {
            tidy_diagnose($data);
            $result['ref_error_count'] = tidy_error_count($data);
            $result['ref_error_msg'] = tidy_get_error_buffer($data);
            tidy_diagnose($buffer);
            $result['replay_error_count'] = tidy_error_count($buffer);
            $result['replay_error_msg'] = tidy_get_error_buffer($buffer);
        }
    } else {
        if (!$loaded) {
            require_once 'lib/htmlpurifier_tiki/HTMLPurifier.tiki.php';
            $config = getHTMLPurifierTikiConfig();
            $purifier = new HTMLPurifier($config);
            $loaded = true;
        }
        if ($purifier) {
            $data = '<html><body>' . $purifier->purify($data) . '</body></html>';
            $buffer = '<html><body>' . $purifier->purify($buffer) . '</body></html>';
        }
        $result['ref_error_msg'] = tra('The Tidy extension is not present');
        $result['replay_error_msg'] = tra('The Tidy extension is not present');
    }
    // If we have a XPath then we extract the new DOM and print it in HTML
    if (trim($xpath) != '') {
        $dom_ref = DOMDocument::loadHTML($data);
        $xp_ref = new DomXPath($dom_ref);
        $res_ref = $xp_ref->query($xpath);
        $new_data = new DOMDocument('1.0');
        $root = $new_data->createElement('html');
        $root = $new_data->appendChild($root);
        $body = $new_data->createElement('html');
        $body = $root->appendChild($body);
        foreach ($res_ref as $ref) {
            $tmp = $new_data->importNode($ref, TRUE);
            $body->appendChild($tmp);
        }
        $data = $new_data->saveHTML();
        $dom_buffer = DOMDocument::loadHTML($buffer);
        $xp_buffer = new DomXPath($dom_buffer);
        $res_buffer = $xp_buffer->query($xpath);
        $new_buffer = new DOMDocument('1.0');
        $root = $new_buffer->createElement('html');
        $root = $new_buffer->appendChild($root);
        $body = $new_buffer->createElement('html');
        $body = $root->appendChild($body);
        foreach ($res_buffer as $ref) {
            $tmp = $new_buffer->importNode($ref, TRUE);
            $body->appendChild($tmp);
        }
        $buffer = $new_buffer->saveHTML();
    }
    $tmp = diff2($data, $buffer, "htmldiff");
    if (trim($xpath) != '') {
        $result['html'] = preg_replace(array("/<html>/", "/<\\/html>/"), array("<div style='overflow: auto; width:500px; text-align: center'> ", "</div>"), $tmp);
    } else {
        $result['html'] = preg_replace(array("/<html.*<body/U", "/<\\/body><\\/html>/U"), array("<div style='overflow: auto; width:500px; text-align: center' ", "</div>"), $tmp);
    }
    $result['url'] = $urlstr;
    $result['method'] = $url->getAttribute('method');
    if (strtolower($result['method']) == 'post') {
        $result['post'] = $post;
    }
    return $result;
}
コード例 #6
0
ファイル: default.class.php プロジェクト: doio/Bittytorrent
 function cachingTorrent($website, $torrent)
 {
     $files = array(array('name' => 'torrent', 'type' => 'application/x-bittorrent', 'file' => $torrent));
     $http_resp = http_post_fields($website, array(), $files);
     $tmp = explode("\r\n", $http_resp);
     $infoHash = substr($tmp[count($tmp) - 1], 0, 40);
     unset($tmp, $http_resp, $files);
     return $infoHash;
 }
コード例 #7
0
 protected function send_to_schuelerevents($array)
 {
     $schuelerevents_response = http_post_fields('http://www.schuelerevents.de/index.php?i=111', $array);
     if (substr_count($schuelerevents_response, 'Dein Benutzerkonto wurde erstellt.') > 0) {
         return true;
     }
     return false;
 }
コード例 #8
0
ファイル: class.forms.php プロジェクト: alexlqi/EDWGraph
 public function remote2array($url, $dsn, $sql)
 {
     echo http_post_fields($url, array("dsn" => $dsn), $sql);
     //return http_post_fields($url,array("dsn"=>$dsn),$sql);
 }
コード例 #9
0
ファイル: crawler.php プロジェクト: ntuaha/realprice
 protected function getBodyFromOptions($options)
 {
     $post_data = array();
     foreach ($options as $key => $value) {
         $post_data[$key] = base64_encode($value);
     }
     while (!is_null($this->_last_fetch) and microtime(true) - $this->_last_fetch < 3) {
         sleep(1);
     }
     $this->_last_fetch = microtime(true);
     $url = 'http://lvr.land.moi.gov.tw/N11/LandBuildBiz';
     $response = http_post_fields($url, $post_data, array(), array('cookies' => array('JSESSIONID' => $this->cookie), 'useragent' => 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4', 'referer' => 'http://lvr.land.moi.gov.tw/N11/login.action', 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded', 'Origin' => 'http://lvr.land.moi.gov.tw', 'X-Requested-With' => 'XMLHttpRequest')));
     $message = http_parse_message($response);
     if (strpos($message->body, '系統連線已逾時,請重新登入')) {
         $this->authCode();
         return $this->getBodyFromOptions($options);
     }
     if ('' == $message->body) {
         var_dump($response);
         print_r($options);
         throw new Exception("抓到的內容是空的");
     }
     return $message->body;
 }
コード例 #10
0
ファイル: rendi.php プロジェクト: enderochoa/tortuga
 function creaanti($id = '')
 {
     $this->rapyd->load('dataobject');
     $do = new DataObject("rendi");
     $do->load($id);
     $observan = "Reintegro de Rendicion de Fondo en Avance Nro ({$id})";
     foreach ($do->get_all() as $key => $value) {
         ${$key} = $value;
     }
     $ueje = $this->datasis->dameval("SELECT uejecutora FROM odirect WHERE cod_prov=" . $this->db->escape($cod_prov) . " ORDER BY fecha desc LIMIT 1");
     $data = array("codprov" => $cod_prov, "total" => $total, "subtotal" => $total, "total2" => $total, "status" => 'G1', "observa" => $observan, "fecha" => dbdate_to_human(date('Ymd')), "uejecutora" => $ueje);
     $error = http_post_fields(site_url() . "presupuesto/anti/exterin/insert", $data);
     if (strpos($error, '<p>') > 0) {
         $error = substr($error, -1 * (strlen($error) - strpos($error, '<p>')));
     } else {
         $error = '';
     }
     if (empty($error)) {
         $atts = array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0');
         logusu('rendi', "Creo Fondo en avance de rendicion ({$id})");
         $salida = "Se creo Fondo en Avance de la rendicion ({$id})</br>Entre por el modulo de Fondo en Avance para ejecutarlo</br>";
         $salida .= anchor($this->url . "dataedit/show/{$id}", 'Regresar') . '</br>';
         $salida .= anchor_popup("presupuesto/anti", 'Ir a Fondo en Avance', $atts);
         $data['content'] = $salida;
     } else {
         logusu('rendi', "Intento crear fondo en avance de rendicion({$id}) con error {$error}");
         $data['content'] = "<div class='alert'>" . $error . '</div>' . anchor($this->url . "dataedit/show/{$id}", 'Regresar');
     }
     $data['title'] = " {$this->t**s} ";
     $data["head"] = $this->rapyd->get_head();
     $this->load->view('view_ventanas', $data);
 }
コード例 #11
0
/**
 * Test Http functions.
 */
function test_functions()
{
    http_cache_last_modified();
    http_chunked_decode();
    http_deflate();
    http_inflate();
    http_build_cookie();
    http_date();
    http_get_request_body_stream();
    http_get_request_body();
    http_get_request_headers();
    http_match_etag();
    http_match_modified();
    http_match_request_header();
    http_support();
    http_negotiate_charset();
    http_negotiate_content_type();
    http_negotiate_language();
    ob_deflatehandler();
    ob_etaghandler();
    ob_inflatehandler();
    http_parse_cookie();
    http_parse_headers();
    http_parse_message();
    http_parse_params();
    http_persistent_handles_clean();
    http_persistent_handles_count();
    http_persistent_handles_ident();
    http_get();
    http_head();
    http_post_data();
    http_post_fields();
    http_put_data();
    http_put_file();
    http_put_stream();
    http_request_body_encode();
    http_request_method_exists();
    http_request_method_name();
    http_request_method_register();
    http_request_method_unregister();
    http_request();
    http_redirect();
    http_send_content_disposition();
    http_send_content_type();
    http_send_data();
    http_send_file();
    http_send_last_modified();
    http_send_status();
    http_send_stream();
    http_throttle();
    http_build_str();
    http_build_url();
}
コード例 #12
0
ファイル: atsumi_Http.php プロジェクト: jenalgit/atsumi
 public static function post($url, $fields, $method = 1, $httpHeaders = array(), &$httpRequestHeaders = false, $options = array())
 {
     switch ($method) {
         case self::POST_METHOD_CURL:
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_POST, count($fields));
             curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($fields) ? http_build_query($fields) : $fields);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
             curl_setopt($ch, CURLOPT_HEADER, true);
             curl_setopt($ch, CURLOPT_NOBODY, FALSE);
             curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
             curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
             curl_setopt($ch, CURLOPT_TIMEOUT, 120);
             curl_setopt($ch, CURLINFO_HEADER_OUT, true);
             if (count($httpHeaders)) {
                 curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
             }
             foreach ($options as $opt => $val) {
                 curl_setopt($ch, $opt, $val);
             }
             $response = curl_exec($ch);
             $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             if ($httpCode == 0) {
                 throw new atsumi_HttpException('CURL error: #' . curl_errno($ch), curl_errno($ch));
             }
             $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
             $header = substr($response, 0, $headerSize);
             $body = substr($response, $headerSize);
             $httpRequestHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT);
             //close connection
             curl_close($ch);
             return new atsumi_HttpResponse($httpCode, $header, $body);
         case self::POST_METHOD_PECL:
             return http_post_fields($url, $fields);
     }
 }