本文整理汇总了PHP中Zend\Http\Client::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setHeaders方法的具体用法?PHP Client::setHeaders怎么用?PHP Client::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: citation
public function citation()
{
parent::results();
$style = $this->request->getParam("style", false, "mla");
$items = array();
$results = $this->response->get("results");
// header("Content-type: application/json");
$x = 1;
foreach ($results->getRecords() as $result) {
$id = "ITEM={$x}";
$record = $result->getXerxesRecord()->toCSL();
$record["id"] = $id;
$items[$id] = $record;
$x++;
}
$json = json_encode(array("items" => $items));
// header("Content-type: application/json"); echo $json; exit;
$url = "http://127.0.0.1:8085?responseformat=html&style={$style}";
$client = new Client();
$client->setUri($url);
$client->setHeaders("Content-type: application/json");
$client->setHeaders("Expect: nothing");
$client->setRawData($json)->setEncType('application/json');
$response = $client->request('POST')->getBody();
echo $response;
exit;
}
示例2: getHttpClient
/**
* Return the singleton instance of the HTTP Client. Note that
* the instance is reset and cleared of previous parameters and
* Authorization header values.
*
* @return Zend\Http\Client
*/
public static function getHttpClient()
{
if (!isset(self::$httpClient)) {
self::$httpClient = new HTTPClient();
} else {
self::$httpClient->setHeaders('Authorization', null);
self::$httpClient->resetParameters();
}
return self::$httpClient;
}
示例3: __construct
/**
* @throws Exception\ConfigWasNotProvided
* @throws Exception\TokenWasNotProvided
*/
public function __construct()
{
if (!self::getConfig()) {
throw new Exception\ConfigWasNotProvided();
}
if (!self::getToken()) {
throw new Exception\TokenWasNotProvided();
}
$this->_client = new \Zend\Http\Client();
$this->_client->setHeaders(['x-auth' => self::getToken()]);
}
示例4: get
/**
* {@inheritDoc}
*/
public function get($uri, array $headers = [])
{
$this->client->resetParameters();
$this->client->setMethod('GET');
$this->client->setHeaders(new Headers());
$this->client->setUri($uri);
if (!empty($headers)) {
$this->injectHeaders($headers);
}
$response = $this->client->send();
return new Response($response->getStatusCode(), $response->getBody(), $this->prepareResponseHeaders($response->getHeaders()));
}
示例5: writeStream
/**
* Write using a stream
*
* @param $path
* @param $resource
* @param null $config
* @return array|bool
*/
public function writeStream($path, $resource, Config $config)
{
$username = 'admin';
$password = '12345678';
$auth = base64_encode($username . ':' . $password);
$this->client->setUri('http://192.168.10.47/api/wstest/upload/fg');
// $this->client->setUri('http://files.local/api/v2/fs');
$this->client->setMethod('POST');
$headers = ['Accept' => '*/*', 'Cache-Control' => 'no-cache', 'Authorization' => 'Basic ' . $auth, 'X-File-Name' => 'todo.txt', 'Content-Type' => 'application/x-www-form-urlencoded'];
$this->client->setHeaders($headers);
file_put_contents('tmp', $resource);
// $this->client->setFileUpload('todo.txt', 'todo_txt', $resource);
$text = 'this is some plain text';
$this->client->setFileUpload('some_text.txt', 'some_text_txt', $text, 'text/plain');
prn($this->client->send()->getContent());
exit;
$location = $this->applyPathPrefix($path);
$config = Util::ensureConfig($config);
$this->ensureDirectory(dirname($location));
$this->client->setMethod('POST');
$this->client->setUri($this->api_url);
$this->client->setParameterPOST(array_merge($this->auth_param, ['filename' => $path]));
$this->client->setHeaders(['wp_path' => $path]);
file_put_contents('tmp', $resource);
$this->client->setFileUpload('tmp', 'form');
$response = $this->client->send();
$path = json_decode($response->getContent())->file_id;
$type = 'wepo_fs';
$result = compact('contents', 'type', 'size', 'path');
if ($visibility = $config->get('visibility')) {
$result['visibility'] = $visibility;
}
return $result;
}
示例6: getClient
protected function getClient($url)
{
$http_client = new HttpClient(null, ['timeout' => $this->timeout]);
$http_client->setHeaders(['User-Agent' => 'OpenErpByJsonRpc by ZendJsonRpc']);
if (null !== $this->cookie) {
$http_client->addCookie($this->cookie);
}
$this->client = new Client($url, $http_client);
return $this->client;
}
示例7: testContentTypeAdditionlInfo
/**
* @group ZF2-78
* @dataProvider parameterArrayProvider
*/
public function testContentTypeAdditionlInfo($params)
{
$content_type = 'application/x-www-form-urlencoded; charset=UTF-8';
$this->client->setUri($this->baseuri . 'testPostData.php');
$this->client->setHeaders(array('Content-Type' => $content_type));
$this->client->setMethod(\Zend\Http\Request::METHOD_POST);
$this->client->setParameterPost($params);
$this->client->send();
$request = Request::fromString($this->client->getLastRawRequest());
$this->assertEquals($content_type, $request->getHeaders()->get('Content-Type')->getFieldValue());
}
示例8: doPostRequest
public function doPostRequest()
{
$url = 'http://www.mvg-live.de/MvgLive/mvglive/rpc/newstickerService';
$client = new Client();
$client->setUri($url);
$client->setMethod(\Zend\Http\Request::METHOD_POST);
$headers = array('Origin' => 'http://www.mvg-live.de', 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,da;q=0.2', 'X-GWT-Module-Base' => 'http://www.mvg-live.de/MvgLive/mvglive/', 'Connection' => 'keep-alive', 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36', 'Content-Type' => 'text/x-gwt-rpc; charset=UTF-8', 'Accept' => '*/*', 'X-GWT-Permutation' => '1DD521F1FA9966B50432692AB421CD55', 'Referer' => 'http://www.mvg-live.de/MvgLive/MvgLive.jsp', 'DNT' => '1');
$client->setHeaders($headers);
$client->setRawBody('7|0|4|http://www.mvg-live.de/MvgLive/mvglive/|7690A2A77A0295D3EC713772A06B8898|de.swm.mvglive.gwt.client.newsticker.GuiNewstickerService|getNewsticker|1|2|3|4|0|');
$response = $client->send();
return $response->getBody();
}
示例9: testCustomHttpClientUserAgentIsNotOverridden
/**
* @group ZF-3288
*/
public function testCustomHttpClientUserAgentIsNotOverridden()
{
$this->assertFalse($this->httpClient->getHeader('user-agent'), 'UA is null if no request was made');
$this->setServerResponseTo(true);
$this->assertTrue($this->xmlrpcClient->call('method'));
$this->assertSame('Zend_XmlRpc_Client', $this->httpClient->getHeader('user-agent'), 'If no custom UA is set, set Zend_XmlRpc_Client');
$expectedUserAgent = 'Zend_XmlRpc_Client (custom)';
$this->httpClient->setHeaders(array('user-agent' => $expectedUserAgent));
$this->setServerResponseTo(true);
$this->assertTrue($this->xmlrpcClient->call('method'));
$this->assertSame($expectedUserAgent, $this->httpClient->getHeader('user-agent'));
}
示例10: testCustomHttpClientUserAgentIsNotOverridden
public function testCustomHttpClientUserAgentIsNotOverridden()
{
$this->assertFalse($this->httpClient->getHeader('User-Agent'), 'UA is null if no request was made');
$this->setServerResponseTo(null);
$this->assertNull($this->jsonClient->call('method'));
$this->assertSame('Zend_Json_Server_Client', $this->httpClient->getHeader('User-Agent'), 'If no custom UA is set, set Zend_Json_Server_Client');
$expectedUserAgent = 'Zend_Json_Server_Client (custom)';
$this->httpClient->setHeaders(array('User-Agent' => $expectedUserAgent));
$this->setServerResponseTo(null);
$this->assertNull($this->jsonClient->call('method'));
$this->assertSame($expectedUserAgent, $this->httpClient->getHeader('User-Agent'));
}
示例11: fetch
/**
* Fetch data from the bug tracker
* @since Version 3.8.7
* @param string $url
* @return array
*/
public function fetch($url)
{
$config = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true));
$client = new Client($url, $config);
$client->setHeaders(array("X-Redmine-API-Key" => self::REDMINE_API_KEY));
$response = $client->send();
$response = $response->getContent();
if (strlen($response) > 1) {
$response = json_decode($response, true);
return $response;
}
throw new Exception("Could not fetch current issues from the bug tracker");
}
示例12: executePost
public static function executePost($uri, $value)
{
$client = new Client();
$client->setUri($uri);
$client->setMethod(Request::METHOD_POST);
$client->setRawBody($value);
$client->setHeaders(array('Content-Type: text/plain'));
$response = $client->send();
if ($response->getStatusCode() >= 300) {
throw new \Exception(sprintf('Request Response: Status Code %d, Url: %s', $response->getStatusCode(), $uri));
}
return $response->getBody();
}
示例13: nearby
public static function nearby($countryCode, $postalCode)
{
$http = new Client();
$http->setOptions(array('sslverifypeer' => false));
$headers = new Headers();
$headers->addHeaderLine('Content-Type', 'application/json');
$http->setHeaders($headers);
$http->setUri(self::$apiUrl . 'nearby/' . urlencode($countryCode) . '/' . urlencode($postalCode));
$http->setMethod('GET');
$response = $http->send();
$json = Json::decode($response->getBody());
return $json;
}
示例14: callRaynetcrmRestApi
/**
* Requests RAYNET Cloud CRM REST API. Check https://s3-eu-west-1.amazonaws.com/static-raynet/webroot/api-doc.html for any further details.
*
* @param $serviceName string URL service name
* @param $method string Http method
* @param $request array request
* @return \Zend\Http\Response response
*/
private function callRaynetcrmRestApi($serviceName, $method, $request)
{
$client = new Client('', array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)));
$client->setMethod($method);
$client->setUri($this->buildUrl($serviceName));
$client->setHeaders(array('X-Instance-Name' => $this->fInstanceName, 'Content-Type' => 'application/json; charset=UTF-8'));
$client->setAuth($this->fUserName, $this->fApiKey);
if ($method === self::HTTP_METHOD_GET) {
$client->setParameterGet($request);
} else {
$client->setRawBody(Json::encode($request));
}
return $client->send();
}
示例15: request
public function request($service, array $params = [], $method = 'POST')
{
$result = false;
try {
$url = sprintf('https://api.superlogica.net/v2/financeiro%s', $service);
$client = new Client($url);
$client->setAdapter(new Curl());
$client->setMethod($method);
$client->setOptions(['curloptions' => [CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]]);
$client->setHeaders($this->authHeader);
if (!empty($params)) {
if ($method == 'GET') {
$client->setParameterGet($params);
} else {
$client->setParameterPost($params);
}
}
$response = $client->send();
if ($response->isSuccess()) {
$body = $response->getContent();
$json = Json\Json::decode($body, 1);
if (!empty($json[0]['status'])) {
if ($json[0]['status'] == '200') {
$result = $json;
}
} else {
$result = $json;
}
}
$isException = false;
} catch (\Zend\Http\Exception\RuntimeException $e) {
$isException = true;
} catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) {
$isException = true;
} catch (Json\Exception\RuntimeException $e) {
$isException = true;
} catch (Json\Exception\RecursionException $e2) {
$isException = true;
} catch (Json\Exception\InvalidArgumentException $e3) {
$isException = true;
} catch (Json\Exception\BadMethodCallException $e4) {
$isException = true;
}
if ($isException === true) {
//código em caso de problemas no decode
}
return $result;
}