我正在尝试使用google-api-php-client创建一个Http put请求。 Oauth工作正常,我可以得到请求,但我无法弄清楚如何进行投注。
//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);
错误是" Content-Type application / x-www-form-urlencoded不是有效的输入类型。"。
似乎它正在尝试发布POST。执行PUT请求的正确方法是什么?
答案 0 :(得分:2)
我找到了。必须在headers参数中设置Content-type值。我认为这是自动完成的。
$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());