setHeader() public méthode

Add extra header to include in the request.
public setHeader ( $key, $value )
$key
$value
 public function send($url, $method, array $parameters = [], array $postParameters = [], array $header = [], $content = '')
 {
     $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $method = strtolower($method);
     $finalUrl = strpos($url, '//') !== false ? $url : $this->url . $url;
     if (!empty($this->authorization) && empty($header['Authorization'])) {
         $authClass = 'Bennsel\\WindowsAzureCurl\\Service\\Authorization\\' . $this->authorization;
         $class = new $authClass($this->settings);
         $header['Authorization'] = $class->getAuthorizationString($url, $method, $parameters, $header);
     }
     if ($content && is_object($content) && method_exists($content, 'toArray')) {
         $parameters = $content->toArray();
     }
     foreach ($header as $key => $value) {
         $this->curl->setHeader($key, $value);
     }
     $orgHeader = $header;
     $r = $this->curl->{$method}($finalUrl, $parameters ?: $postParameters);
     if ($this->curl->http_status_code == 301) {
         $this->url = $this->curl->response_headers['Location'];
         return $this->send($url, $method, $parameters, $postParameters, $orgHeader, $content);
     }
     return ResponseModelMapping::create($url, $r);
 }
Exemple #2
0
 protected function _processTask()
 {
     try {
         $curl = new Curl();
         $curl->setUserAgent('got/Tarth');
         if ($this->includeTarthHeader) {
             $curl->setHeader(\Tarth\Tool\Task::HEADER_ALLERIA_CRC, \Tarth\Tool\Task::getTarthHeader($this));
         }
         if (isset($this->header)) {
             foreach ($this->header as $key => $value) {
                 $curl->setHeader($key, $value);
             }
         }
         call_user_func_array(array($curl, strtolower($this->method)), array($this->url, $this->data));
         if ($curl->error) {
             return false;
         } else {
             //响应码大于300为请求失败
             return $curl->httpStatusCode < 300;
             //接口返回为json格式,返回值中有code为0
             //return $curl->response->code == 0;
         }
     } catch (Exception $e) {
     }
 }
 /**
  * @author mohuishou<*****@*****.**>
  * @return $this
  * @throws \Exception
  */
 protected function login()
 {
     //判断是否已经登录
     if (!empty($this->_login_cookie)) {
         return $this;
     }
     //设置header伪造来源以及ip
     $ip = rand(1, 233) . '.' . rand(1, 233) . '.' . rand(1, 233) . '.' . rand(1, 233);
     $this->_curl->setHeader("X-Forwarded-For", $ip);
     $this->_curl->setHeader("Referer", 'http://202.115.47.141/login.jsp');
     $param = ["zjh" => $this->_uid, "mm" => $this->_password];
     $this->_curl->post('http://202.115.47.141/loginAction.do', $param);
     if ($this->_curl->error) {
         throw new \Exception('Error: ' . $this->_curl->errorCode . ': ' . $this->_curl->errorMessage, 5001);
     }
     //判断是否登录成功
     $page = $this->_curl->response;
     $page = iconv('GBK', 'UTF-8//IGNORE', $page);
     $rule = ['err' => ['.errorTop', 'text']];
     $err = QueryList::Query($page, $rule)->data;
     if (!empty($err)) {
         throw new \Exception('Error:' . $err[0]['err'], 4011);
     }
     //登录成功之后设置cookie
     $this->_login_cookie = $this->_curl->getResponseCookie("JSESSIONID");
     $this->_curl->setCookie('JSESSIONID', $this->_login_cookie);
     return $this;
 }
Exemple #4
0
 /**
  *
  * @param string $query
  * @return
  * @throw
  */
 public function sendSparqlUpdateQuery($query)
 {
     // TODO extend Accept headers to further formats
     $this->client->setHeader("Accept", "application/sparql-results+json");
     $this->client->setHeader("Content-Type", "application/sparql-update");
     return $this->client->get($this->url, array("query" => $query));
 }
Exemple #5
0
 /**
  * 请求服务器
  * @param string $method
  * @param $path
  * @param $data
  * @return null
  */
 protected function _request($path, $data, $method = 'POST')
 {
     $this->_client->setHeader('X-AVOSCloud-Application-Id', $this->appId);
     $this->_client->setHeader('X-AVOSCloud-Application-Key', $this->appKey);
     $this->_client->setHeader('Content-Type', 'application/json');
     $this->_client->{$method}($this->apiUrl . $path, Json::encode($data));
     return $this->_client->response;
 }
Exemple #6
0
 /**
  * @param string $apiKey
  * @param string $version
  * @param string $host
  */
 public function __construct($apiKey, $version = 'v1', $host = 'https://api.persistiq.com')
 {
     $this->apiKey = $apiKey;
     $this->version = $version;
     $this->host = $host;
     $this->curl = new Curl($host . '/' . $version . '/');
     $this->curl->setHeader('x-api-key', $apiKey);
     $this->curl->setHeader('Content-Type', 'application/json');
 }
Exemple #7
0
 public function setUp()
 {
     $this->client = Login::authenticate();
     $cookies = $this->client->getRequest()->getCookies();
     $curl = new Curl();
     $curl->setHeader('User-Agent', Login::$ua);
     $curl->setHeader('Cookie', Login::setCookie($cookies));
     $this->curl = $curl;
 }
 public function appointmentsTimeline()
 {
     $curl = new Curl();
     $curl->setHeader("X-Parse-Application-Id", "yPPe3Uv46pKNnrTc7I6xArFHi8EQ8cdz4Kw3JGkX");
     $curl->setHeader("X-Parse-REST-API-Key", "7PJB1F4g8aFSv5f8e0gSMwi9Ghv2AeAkTW0O50pe");
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $curl->get('http://52.24.133.167/stripe/index.php/api/v1/history/appointments');
     return $curl->response;
 }
Exemple #9
0
 /**
  * Make the call
  *
  * @author Koen Blokland Visser
  *
  * @param $hash
  * @param $callId
  *
  * @return array
  */
 public function __construct($hash, $callId)
 {
     $curl = new Curl();
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('Accept', 'application/json');
     $curl->setHeader('Hash', $hash);
     $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $curl->get('https://api.voipgrid.nl/api/clicktodial/' . $callId . '/');
     /** @var array $response */
     $this->response = json_decode($curl->response, true);
 }
 public function sendTopic($topic, $param)
 {
     $this->validate($topic, $param);
     $data = array('to' => $topic, 'data' => $param);
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('Authorization', "key={$this->key}");
     $curl->post($this->gcm_link, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
     if ($curl->error) {
         throw new \Exception("Curl Post Error : " . $curl->error_message);
     }
     return $curl->response;
 }
Exemple #11
0
 public function __construct($login, $hash, $subdomain, ICookieContainer $cookieContainer)
 {
     $this->_login = $login;
     $this->_hash = $hash;
     $this->_subdomain = $subdomain;
     $this->cookieContainer = $cookieContainer;
     $this->_curl = new Curl();
     $this->_curl->setUserAgent('amoCRM-API-client/1.0');
     $this->_curl->setHeader('Content-Type', 'application/json');
     $this->_curl->setOpt(CURLOPT_HEADER, false);
     $this->_curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
     $this->_curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
     $this->auth();
 }
Exemple #12
0
 /**
  * Apply cURL options
  */
 private function applyCurlOptions()
 {
     $this->curl->reset();
     $this->curl->setUserAgent('Shopello-PHP API Client/1.0');
     $this->curl->setHeader('X-API-KEY', $this->apiKey);
     $this->curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->curl->setOpt(CURLOPT_HEADER, false);
     $this->curl->setOpt(CURLOPT_NOBODY, false);
     $this->curl->setOpt(CURLOPT_CONNECTTIMEOUT, 3);
     $this->curl->setOpt(CURLOPT_TIMEOUT, 300);
     foreach ($this->curlOptions as $key => $value) {
         $this->curl->setOpt($key, $value);
     }
 }
Exemple #13
0
 public function postData($api_url, $api_opts = FALSE)
 {
     $curl = new Curl();
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('Authorization', 'Bearer ' . $_SESSION['access_token']);
     $curl->post($api_url, $api_opts);
     if ($this->debug) {
         var_dump($curl);
     }
     if ($curl->error) {
         return $this->apiError($curl->response);
     } else {
         return array('Eskimo' => $curl->response);
     }
 }
Exemple #14
0
 /**
  * docomoの対話APIを叩いてレスポンスを貰ってくる
  *
  * @param string $apikey    docomoAPIキー
  * @param string $context   会話のコンテキストID(API仕様参照)
  * @param string $mode      会話のモード(API仕様参照
  * @param string $nickname  会話している人間側の名前
  * @param string $text      人間側の入力テキスト
  * @return stdClass         レスポンスのJSONをデコードしたオブジェクト
  * @throws \Exception       サーバとの通信に失敗した場合
  */
 private function getData($apikey, $context, $mode, $nickname, $text)
 {
     $userData = ['utt' => (string) $text, 'context' => (string) $context, 'nickname' => (string) $nickname, 'mode' => (string) $mode];
     $url = sprintf('https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=%s', rawurlencode($apikey));
     Log::info("docomo対話APIを呼び出します");
     Log::info("URL: " . $url);
     Log::info("パラメータ:");
     Log::info($userData);
     $curl = new Curl();
     $curl->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $ret = $curl->post($url, json_encode($userData));
     if ($curl->error) {
         Log::error(sprintf("docomo対話APIの呼び出しに失敗しました: %d: %s", $curl->error_code, $curl->error_message));
         throw new \Exception('docomo dialogue error: ' . $curl->error_code . ': ' . $curl->error_message);
     }
     Log::info("docomoからのデータ:");
     Log::info($ret);
     if (is_object($ret) && isset($ret->utt)) {
         if ($ret->utt == '') {
             Log::warning("  docomo 指示文章が空です");
         } else {
             Log::success("  docomo 指示文章: " . $ret->utt);
         }
         return $ret;
     }
     Log::error("docomoから受け取ったデータが期待した形式ではありません:");
     Log::error($ret);
     throw new \Exception('Received an unexpected data from docomo server');
 }
Exemple #15
0
 protected function _html()
 {
     $curl = new Curl();
     $curl->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36');
     $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     $html = $curl->get($this->url);
     return $html;
 }
 /**
  * @param RequestInterface $request
  * @return ResponseInterface
  * @throws InvalidArgumentException
  */
 public function sendRequest(RequestInterface $request)
 {
     foreach ($request->getHeaders() as $name => $value) {
         $this->curlClient->setHeader($name, $value);
     }
     switch ($request->getMethod()) {
         case RequestInterface::METHOD_POST:
             $this->curlClient->post($request->getUrl(), $request->getBody());
             break;
         default:
             throw new InvalidArgumentException('Unsupported http request method ' . $request->getMethod(), 0, null, null, null);
     }
     if ($this->curlClient->curl_error === true) {
         throw new HttpClientException($this->curlClient->curl_error_message);
     }
     $response = new Response((int) $this->curlClient->http_status_code, $this->curlClient->raw_response);
     return $response;
 }
 private function connect()
 {
     $curl = new Curl();
     $curl->setBasicAuthentication($this->adminUsername, $this->adminPassword);
     $curl->setUserAgent('');
     $curl->setReferrer('');
     $curl->setHeader('X-Requested-With', 'XMLHttpRequest');
     $this->curl = $curl;
 }
Exemple #18
0
 private function _call($method, $name, $parameters = array())
 {
     $urlParameters = array();
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setHeader('Authorization', 'Bearer ' . $this->accessToken);
     $curl->setHeader('Accept', $this->outputFormat);
     if ($this->outputFormat === self::OUTPUT_FORMAT_JSONP) {
         $urlParameters['callback'] = $this->jsonpFunctionName;
     }
     if ($method === 'get') {
         $curl->get(self::HOST . $name . '/?' . http_build_query($urlParameters), $parameters);
     } else {
         $curl->post(self::HOST . $name . '/?' . http_build_query($urlParameters), $parameters);
     }
     if ($curl->error) {
         echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
     } else {
         echo $curl->raw_response;
     }
 }
Exemple #19
0
 /**
  * Set auth method for curl request
  *
  * @param string "apikey" or "basic"
  */
 private function setAuthMethod($authMethod)
 {
     switch ($authMethod) {
         case 'apikey':
             $this->curl->setHeader('X-API-KEY', $this->apiKey);
             break;
         case 'basic':
         default:
             $this->curl->setBasicAuthentication($this->apiUsername, $this->apiPassword);
             break;
     }
 }
Exemple #20
0
 public static function ip($ip)
 {
     $url = 'http://apis.baidu.com/rtbasia/ip_type/ip_type?ip=' . $ip;
     $curl = new Curl();
     $curl->setHeader("apikey", "58d0d55af6ee8cda005ec2d674ff0db2");
     $curl->get($url);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
 public function call($function, $request_type = "GET", $fields = null)
 {
     $url = "https://api." . $this->coinbaseUrl . ".com/v2/" . $function;
     $time = time();
     $fields_json = null;
     $message = $time . $request_type . "/v2/" . $function;
     if ($fields) {
         $fields_json = json_encode($fields);
         $message .= $fields_json;
     }
     $signature = hash_hmac("sha256", $message, $this->apiSecret);
     $curl = new Curl();
     $curl->setHeader("Content-Type", "application/json");
     $curl->setHeader("CB-ACCESS-KEY", $this->apiKey);
     $curl->setHeader("CB-ACCESS-SIGN", $signature);
     $curl->setHeader("CB-ACCESS-TIMESTAMP", $time);
     if ($request_type == "GET") {
         $curl->get($url, $fields_json);
     } elseif ($request_type == "POST") {
         $curl->post($url, $fields_json);
     }
     return $curl->response;
 }
 /**
  *
  * @param $uri
  * @param $method
  * @param array $params
  * @return mixed
  */
 protected function fetch_from_url($uri, $method, $params = array())
 {
     $method = strtolower($method);
     if (!in_array($method, array('post', 'get', 'put', 'delete'))) {
         throw new Exception('HTTP Method is not allowed.');
     }
     $url = $this->api_prefix . $uri;
     foreach ($params as $key => $value) {
         if (is_bool($value)) {
             $params[$key] = $value ? 'true' : 'false';
         }
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setHeader('Host', $this->headers['Host']);
     $curl->setHeader('Authorization', $this->headers['Authorization']);
     $curl->setHeader('User-Agent', $this->headers['User-Agent']);
     $curl->{$method}($url, $params);
     $result = $curl->response;
     $curl->close();
     $array = json_decode(json_encode($result), true);
     return $array;
 }
 public function scrape($locale = 'en-us', $user_agent = false, $proxy = false)
 {
     $curl = new Curl();
     $curl->setHeader('Accept-Language', $locale);
     $curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
     if ($user_agent) {
         $curl->setOpt(CURLOPT_USERAGENT, $user_agent);
     }
     if ($proxy) {
         $curl->setOpt(CURLOPT_PROXY, $proxy);
         //            $curl->setOpt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
     }
     $curl->get($this->trends_url);
     if ($curl->error) {
         throw new FailedRetrieveTrendsException('Error #' . $curl->error_code . ': ' . $curl->error_message);
     }
     $this->parseTrendsFromResponse($curl->response);
 }
Exemple #24
0
 private function post($json, $headers)
 {
     $curl = new Curl();
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('apikey', strval($this->apiKey));
     $curl->setHeader('token', strval($this->merchantToken));
     $curl->setHeader('Authorization', $headers['authorization']);
     $curl->setHeader('nonce', $headers['nonce']);
     $curl->setHeader('timestamp', $headers['timestamp']);
     $curl->post($this->uri, $json);
     $curl->close();
     return $curl->response;
 }
Exemple #25
0
	public function delete_stream($delete_key)
	{
		$curl = new Curl();
		$curl->setHeader('Phant-Delete-Key', $delete_key);
		$curl->delete($this->server_hostname . '/streams/' . $this->public_key);
		
		if ($curl->error) 
		{
	    return array(
				'http_status' => $curl->response_headers['Status-Line']
			);
		}
		else
		{
	    return array(
				'http_status' => $curl->response_headers['Status-Line']
			);
		}
		
	}
Exemple #26
0
 public function process($body, $retry = 0)
 {
     try {
         $data = ['webhook_event' => $body];
         $signature = new Signature($this->signature_key);
         $curl = new Curl();
         $curl->setHeader('X-BOT2HOOK-SIGNATURE', $signature->generate($this->config['webhook_url'], $data));
         $response = $curl->post($this->config['webhook_url'], $data);
         if (empty($response) || !is_object($response) || empty($response->ok)) {
             $error = "Outgoing webhook error. ";
             if (empty($response)) {
                 $error .= 'Curl: ' . $curl->curlErrorCode . ' - ' . $curl->curlErrorMessage . "\n";
             } else {
                 $error .= 'Response: ' . print_r($response, true) . "\n";
             }
             throw new \Exception($error);
         }
     } catch (\Exception $e) {
         $this->retry($e, 'b2h_outgoing', $body, $retry);
     }
 }
Exemple #27
0
 /**
  * 登录
  *
  * @param $user
  * @param $pwd
  * @param $refresh_token
  */
 public function login($user = null, $pwd = null, $refresh_token = null)
 {
     $request = array('client_id' => $this->oauth_client_id, 'client_secret' => $this->oauth_client_secret);
     if ($user != null && $pwd != null) {
         $request = array_merge($request, array('username' => $user, 'password' => $pwd, 'grant_type' => 'password'));
     } elseif ($refresh_token != null || $this->refresh_token != null) {
         $request = array_merge($request, array('grant_type' => 'refresh_token', 'refresh_token' => $refresh_token || $this->refresh_token));
     } else {
         throw new Exception('login params error.');
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setHeader('Authorization', $this->headers['Authorization']);
     $curl->post($this->oauth_url, $request);
     $result = $curl->response;
     $curl->close();
     if (isset($result->has_error)) {
         throw new Exception('Login error: ' . $result->errors->system->message);
     }
     $this->setAuthorizationResponse($result->response);
     $this->setAccessToken($result->response->access_token);
     $this->setRefreshToken($result->response->refresh_token);
 }
Exemple #28
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Curl\Curl;
// curl \
//     -X POST \
//     -d "{"id":"1","content":"Hello world!","date":"2015-06-30 19:42:21"}" \
//     "https://httpbin.org/post"
$url = 'http://openapi.aodianyun.com/v2/LSS.GetAppLiveStatus';
$data = array('access_id' => '310902426204', 'access_key' => '4y4MWt8x7enylydwDkdh4m7Xg49turCM', 'appid' => 'test-lss', "stream" => "test");
$curl = new Curl();
$curl->setHeader('Content-Type', 'application/json');
$curl->post($url, $data);
var_dump($curl->post($url, $data));
 public function testRequestHeaderCaseSensitivity()
 {
     $content_type = 'application/json';
     $curl = new Curl();
     $curl->setHeader('Content-Type', $content_type);
     $reflector = new ReflectionClass('\\Curl\\Curl');
     $property = $reflector->getProperty('headers');
     $property->setAccessible(true);
     $headers = $property->getValue($curl);
     $this->assertEquals($content_type, $headers['Content-Type']);
     $this->assertEquals($content_type, $headers['content-type']);
     $this->assertEquals($content_type, $headers['CONTENT-TYPE']);
     $this->assertEquals($content_type, $headers['cOnTeNt-TyPe']);
 }
Exemple #30
0
 /**
  * Configure Curl.
  *
  * @param Curl $curl
  * @param string $serverApiKey
  */
 protected static function configCurl(&$curl, $serverApiKey)
 {
     $curl->setUserAgent('PhpGcmQueue 2');
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
     $curl->setHeader('Authorization', 'key=' . $serverApiKey);
     $curl->setHeader('Content-Type', 'application/json');
 }