【问题标题】:Google api php client - Http put requestGoogle api php 客户端 - Http put 请求
【发布时间】:2012-08-15 20:19:47
【问题描述】:

我正在尝试使用 google-api-php-client 创建一个 Http 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);

得到的错误是“Content-Type application/x-www-form-urlencoded 不是有效的输入类型。”。

它似乎正在尝试进行 POST。执行 PUT 请求的正确方法是什么?

【问题讨论】:

    标签: php google-api google-api-client


    【解决方案1】:

    我找到了。 Content-type 值必须在 headers 参数中设置。我认为它是自动完成的。

    $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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-26
      • 1970-01-01
      • 2013-04-06
      • 2022-08-16
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多