本文整理汇总了PHP中GuzzleHttp\Client::put方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::put方法的具体用法?PHP Client::put怎么用?PHP Client::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResponse
private function getResponse($stack, $base_uri, $uri, $data, $httpMethod)
{
$middleware = new Oauth1(['consumer_key' => self::CONSUMER_KEY, 'consumer_secret' => self::CONSUMER_SECRET, 'token_secret' => self::TOKEN_SECRET]);
//'auth' => ['user_name', 'pass_name'], // when using username & password
$options = ['auth' => 'oauth', 'debug' => false, 'headers' => ['Accept' => 'application/hal+json', 'Content-Type' => 'application/hal+json'], 'body' => json_encode($data)];
$stack->push($middleware);
$client = new Client(['base_uri' => $base_uri, 'handler' => $stack]);
$response = false;
switch ($httpMethod) {
case self::HTTP_GET:
$response = $client->get($uri, $options);
break;
case self::HTTP_POST:
$response = $client->post($uri, $options);
break;
case self::HTTP_PUT:
$response = $client->put($uri, $options);
break;
case self::HTTP_PATCH:
$response = $client->patch($uri, $options);
break;
case self::HTTP_DELETE:
$response = $client->delete($uri, $options);
break;
}
return $response;
}
示例2: makeHttpRequest
function makeHttpRequest($method, $url, $apiRequest = null, $queryString = null)
{
$urlEndPoint = $this->apiConfiguration->getDefaultEndPoint() . '/' . $url;
$data = ['headers' => ['Authorization' => 'Bearer ' . $this->apiConfiguration->getAccessToken()], 'json' => $apiRequest, 'query' => $queryString];
try {
switch ($method) {
case 'post':
$response = $this->guzzle->post($urlEndPoint, $data);
break;
case 'put':
$response = $this->guzzle->put($urlEndPoint, $data);
break;
case 'delete':
$response = $this->guzzle->delete($urlEndPoint, $data);
break;
case 'get':
$response = $this->guzzle->get($urlEndPoint, $data);
break;
default:
throw new \Exception('Missing request method!');
}
if (in_array(current($response->getHeader('Content-Type')), ['image/png', 'image/jpg'])) {
$result = $response->getBody()->getContents();
} else {
$result = json_decode($response->getBody(), true);
}
return $result;
} catch (ConnectException $c) {
throw $c;
} catch (RequestException $e) {
throw $e;
}
}
示例3: post
/**
* Make a post request to shorte.st.
*
* @param $url_to_shorten
*
* @return \GuzzleHttp\Stream\StreamInterface|null|\Psr\Http\Message\StreamInterface
*/
private function post($url_to_shorten)
{
// Prepare the request.
$request = $this->client->put(Shortest::BASE_URL, ['headers' => ['public-api-token' => $this->config->get('shortest.api_token')], 'form_params' => ['urlToShorten' => $url_to_shorten]]);
// Return the body as json.
return $request->getBody();
}
示例4: put
public function put($resource, $body, $type, $options = [])
{
$options['body'] = $this->serializer->serialize($body, 'json');
$options['headers'] = ['Content-Type' => 'application/json'];
$content = $this->client->put($resource, $options)->getBody()->getContents();
return $this->deserialize($content, $type);
}
示例5: updateObject
public function updateObject($object, ChangeSet $changeSet)
{
$data = $this->prepareUpdateChangeSet($object, $changeSet);
$identifier = $this->getObjectIdentifier($object);
$class = $this->objectManager->getClassMetadata(get_class($object));
$url = sprintf('%s/%s', $this->url, $identifier[$class->identifier[0]]);
return $this->client->put($url, array('body' => $data))->json();
}
示例6: testUpdateSchedule
public function testUpdateSchedule()
{
$response = self::$client->put('/');
$updatedSchedule = Schedule::create($response->json());
$this->assertInstanceOf('Ctct\\Components\\EmailMarketing\\Schedule', $updatedSchedule);
$this->assertEquals(1, $updatedSchedule->id);
$this->assertEquals("2012-12-16T11:07:43.626Z", $updatedSchedule->scheduled_date);
}
示例7: run
/**
* @param string $testId
* @return int result_id
*/
public function run($testId)
{
$url = sprintf(static::API_BASE_URL . '/tests/%s/run', $testId);
$response = $this->client->put($url);
if (empty($response->getBody())) {
return null;
}
return $response->json(['object' => true])->result_id;
}
示例8: testUpdateList
public function testUpdateList()
{
$response = self::$client->put('/');
$list = ContactList::create($response->json());
$this->assertInstanceOf('Ctct\\Components\\Contacts\\ContactList', $list);
$this->assertEquals(6, $list->id);
$this->assertEquals("Test List 4", $list->name);
$this->assertEquals("HIDDEN", $list->status);
$this->assertEquals(19, $list->contact_count);
}
示例9: shouldRespondToMultipleRequestsWithTheSameResponse
/** @test */
public function shouldRespondToMultipleRequestsWithTheSameResponse()
{
$mockResponse = $this->createResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['hello' => 'world', 'howareyou' => 'today']))));
$this->httpMock->shouldReceiveRequest()->once()->withUrl('http://example.com/foo')->withMethod('PUT')->withQueryParams(['faz' => 'baz'])->withJsonBodyParams(['shakeyo' => 'body'])->andRespondWith($mockResponse);
$this->httpMock->shouldReceiveRequest()->once()->withUrl('http://example.com/foo')->withMethod('PUT')->withQueryParams(['faz' => 'baz'])->withJsonBodyParams(['shakeyo' => 'hands in the air like you just don\'t care'])->andRespondWith($mockResponse);
$actualResponse = $this->guzzleClient->put('http://example.com/foo', ['query' => ['faz' => 'baz'], 'body' => json_encode(['shakeyo' => 'body']), 'headers' => ['Content-Type' => 'application/json']]);
$actualResponse2 = $this->guzzleClient->put('http://example.com/foo', ['query' => ['faz' => 'baz'], 'body' => json_encode(['shakeyo' => 'hands in the air like you just don\'t care']), 'headers' => ['Content-Type' => 'application/json']]);
$this->httpMock->verify();
$this->assertSame($mockResponse, $actualResponse);
$this->assertSame($mockResponse, $actualResponse2);
}
示例10: put
public function put($resource, $body, $type, $options = [])
{
$options['future'] = true;
$options['body'] = $this->serializer->serialize($body, 'json');
$options['headers'] = ['Content-Type' => 'application/json'];
return $this->client->put($resource, $options)->then(function (Response $reponse) {
return $reponse->getBody()->getContents();
})->then(function ($content) use($type) {
return $this->deserialize($content, $type);
});
}
示例11: testNoCacheOtherMethod
public function testNoCacheOtherMethod()
{
$this->client->post("anything");
$response = $this->client->post("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
$this->client->put("anything");
$response = $this->client->put("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
$this->client->delete("anything");
$response = $this->client->delete("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
$this->client->patch("anything");
$response = $this->client->patch("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
}
示例12: testNoCacheOtherMethod
public function testNoCacheOtherMethod()
{
$this->client->post('anything');
$response = $this->client->post('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
$this->client->put('anything');
$response = $this->client->put('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
$this->client->delete('anything');
$response = $this->client->delete('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
$this->client->patch('anything');
$response = $this->client->patch('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
}
示例13: makeRequest
public static function makeRequest($request, $url, $getRawResponse = false)
{
$client = new Client();
switch ($request->getActionType()) {
case ActionType::GET:
if ($getRawResponse) {
return $client->get($url);
} else {
$response = GuzzleHelper::getAsset($url);
//$client->get($url);
}
break;
case ActionType::DELETE:
$response = $client->delete($url);
break;
case ActionType::PUT:
$response = $client->put($url);
break;
case ActionType::POST:
$response = $client->post($url);
break;
default:
$response = GuzzleHelper::getAsset($url);
//$client->get($url);
}
return $response;
}
示例14: put
public static function put($url, $data)
{
$result = [];
$client = new Client();
try {
$response = $client->put($url, ['body' => json_encode($data)]);
$result = $response->getBody();
if ($result->isReadable()) {
return $result->__toString();
} else {
return null;
}
} catch (\GuzzleHttp\Exception\ClientErrorResponseException $e) {
//$resp = $e->getResponse();
return null;
} catch (\GuzzleHttp\Exception\ServerErrorResponseException $e) {
return null;
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
return null;
} catch (\GuzzleHttp\Exception\ClientException $e) {
return null;
} catch (Exception $e) {
return null;
}
}
示例15: testStreamAttributeKeepsStreamOpen
public function testStreamAttributeKeepsStreamOpen()
{
Server::flush();
Server::enqueue("HTTP/1.1 200 OK\r\nFoo: Bar\r\nContent-Length: 8\r\n\r\nhi there");
$client = new Client(['base_url' => Server::$url, 'adapter' => new StreamAdapter(new MessageFactory())]);
$response = $client->put('/foo', ['headers' => ['Foo' => 'Bar'], 'body' => 'test', 'stream' => true]);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('OK', $response->getReasonPhrase());
$this->assertEquals('8', $response->getHeader('Content-Length'));
$body = $response->getBody();
if (defined('HHVM_VERSION')) {
$this->markTestIncomplete('HHVM has not implemented this?');
}
$this->assertEquals('http', $body->getMetadata()['wrapper_type']);
$this->assertEquals(8, $body->getMetadata()['unread_bytes']);
$this->assertEquals(Server::$url . 'foo', $body->getMetadata()['uri']);
$this->assertEquals('hi', $body->read(2));
$body->close();
$sent = Server::received(true)[0];
$this->assertEquals('PUT', $sent->getMethod());
$this->assertEquals('/foo', $sent->getResource());
$this->assertEquals('127.0.0.1:8125', $sent->getHeader('host'));
$this->assertEquals('Bar', $sent->getHeader('foo'));
$this->assertTrue($sent->hasHeader('user-agent'));
}