本文整理汇总了PHP中Curl\Curl::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::setHeader方法的具体用法?PHP Curl::setHeader怎么用?PHP Curl::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Curl\Curl
的用法示例。
在下文中一共展示了Curl::setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
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);
}
示例2: _processTask
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) {
}
}
示例3: login
/**
* @author mohuishou<1@lailin.xyz>
* @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;
}
示例4: sendSparqlUpdateQuery
/**
*
* @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));
}
示例5: _request
/**
* 请求服务器
* @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;
}
示例6: __construct
/**
* @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');
}
示例7: setUp
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;
}
示例8: appointmentsTimeline
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;
}
示例9: __construct
/**
* 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);
}
示例10: sendTopic
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;
}
示例11: __construct
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();
}
示例12: applyCurlOptions
/**
* 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);
}
}
示例13: postData
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);
}
}
示例14: getData
/**
* 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');
}
示例15: _html
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;
}