简体   繁体   English

谷歌api php客户端 - Http put请求

[英]Google api php client - Http put request

I'm trying to create a Http put request with google-api-php-client. 我正在尝试使用google-api-php-client创建一个Http put请求。 Oauth is working fine and I can do get requests but I just can't figure out how to do a put. Oauth工作正常,我可以得到请求,但我无法弄清楚如何做一个put。

//While looping over my contacts
$apiClient = new ApiClient();
$apiClient->setAccessToken($this->Auth->user('google_oauth2_token'));

//Getting fresh XML data since I transformed mine into an array
$contactGetRequest = new apiHttpRequest($contact['link'][1]['@href'], 'GET', array('GData-Version' => 3.0));   
$rawContactData = $apiClient->getIo()->authenticatedRequest($contactGetRequest);

$contactXml = Xml::build($rawContactData->getResponseBody());

//Not changing anything, just trying to do a PUT request
$contactPutRequest = new apiHttpRequest($contact['link'][2]['@href'], 'PUT', array('GData-Version' => 3.0), $contactXml->asXML());
$response = $apiClient->getIo()->authenticatedRequest($contactPutRequest);

The error is getting is "Content-Type application/x-www-form-urlencoded is not a valid input type.". 错误是“Content-Type application / x-www-form-urlencoded不是有效的输入类型。”。

It seems that it's trying to do a POST. 它似乎正在尝试POST。 What is the correct way to do a PUT request? 执行PUT请求的正确方法是什么?

I found it. 我找到了。 The Content-type value has to be set in the headers parameter. 必须在headers参数中设置Content-type值。 I tought it was done automatically. 我认为这是自动完成的。

$contactPutRequest = new apiHttpRequest($contact['link'][2]['@href'], 'PUT', array('GData-Version' => 3.0, 'Content-type' => 'application/atom+xml; charset=UTF-8; type=entry'), $contactXml->asXML());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM