本文整理汇总了PHP中Google_HttpRequest::setPostBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_HttpRequest::setPostBody方法的具体用法?PHP Google_HttpRequest::setPostBody怎么用?PHP Google_HttpRequest::setPostBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_HttpRequest
的用法示例。
在下文中一共展示了Google_HttpRequest::setPostBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProcessEntityRequest
public function testProcessEntityRequest()
{
$io = new Google_CurlIO();
$req = new Google_HttpRequest("http://localhost.com");
$req->setRequestMethod("POST");
// Verify that the content-length is calculated.
$req->setPostBody("{}");
$io->processEntityRequest($req);
$this->assertEquals(2, $req->getRequestHeader("content-length"));
// Test an empty post body.
$req->setPostBody("");
$io->processEntityRequest($req);
$this->assertEquals(0, $req->getRequestHeader("content-length"));
// Test a null post body.
$req->setPostBody(null);
$io->processEntityRequest($req);
$this->assertEquals(0, $req->getRequestHeader("content-length"));
// Set an array in the postbody, and verify that it is url-encoded.
$req->setPostBody(array("a" => "1", "b" => 2));
$io->processEntityRequest($req);
$this->assertEquals(7, $req->getRequestHeader("content-length"));
$this->assertEquals(Google_CurlIO::FORM_URLENCODED, $req->getRequestHeader("content-type"));
$this->assertEquals("a=1&b=2", $req->getPostBody());
// Verify that the content-type isn't reset.
$payload = array("a" => "1", "b" => 2);
$req->setPostBody($payload);
$req->setRequestHeaders(array("content-type" => "multipart/form-data"));
$io->processEntityRequest($req);
$this->assertEquals("multipart/form-data", $req->getRequestHeader("content-type"));
$this->assertEquals($payload, $req->getPostBody());
}
示例2: execute
public function execute()
{
$body = '';
/** @var Google_HttpRequest $req */
foreach ($this->requests as $key => $req) {
$body .= "--{$this->boundary}\n";
$body .= $req->toBatchString($key) . "\n";
}
$body = rtrim($body);
$body .= "\n--{$this->boundary}--";
$url = $GLOBALS['googleApiConfig']['basePath'] . '/batch';
$httpRequest = new Google_HttpRequest($url, 'POST');
$httpRequest->setRequestHeaders(array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary));
$httpRequest->setPostBody($body);
$response = Google_Client::$io->makeRequest($httpRequest);
$response = $this->parseResponse($response);
return $response;
}
示例3: processEntityRequest
/**
* @visible for testing
* Process an http request that contains an enclosed entity.
* @param Google_HttpRequest $request
* @return Google_HttpRequest Processed request with the enclosed entity.
*/
public function processEntityRequest(Google_HttpRequest $request)
{
$postBody = $request->getPostBody();
$contentType = $request->getRequestHeader("content-type");
// Set the default content-type as application/x-www-form-urlencoded.
if (false == $contentType) {
$contentType = self::FORM_URLENCODED;
$request->setRequestHeaders(array('content-type' => $contentType));
}
// Force the payload to match the content-type asserted in the header.
if ($contentType == self::FORM_URLENCODED && is_array($postBody)) {
$postBody = http_build_query($postBody, '', '&');
$request->setPostBody($postBody);
}
// Make sure the content-length header is set.
if (!$postBody || is_string($postBody)) {
$postsLength = strlen($postBody);
$request->setRequestHeaders(array('content-length' => $postsLength));
}
return $request;
}