本文整理匯總了PHP中HTTPRequest::setPostFields方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTTPRequest::setPostFields方法的具體用法?PHP HTTPRequest::setPostFields怎麽用?PHP HTTPRequest::setPostFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::setPostFields方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array
<?php
$url = "http://requestb.in/example";
$data = array("name" => "Lorna", "email" => "lorna@example.com");
$request = new HTTPRequest($url, HTTP_METH_POST);
$request->setPostFields($data);
$request->setHeaders(array("Content-Type" => "application/javascript"));
$request->send();
$result = $request->getResponseBody();
var_dump($result);
示例2: HTTPRequest
/*
* Doc Raptor simple PHP example
* requires pecl_http extension
*
* This is a simple example of creating an excel file and saving it
* using Doc Raptor
*
* For other usage and examples, visit:
* http://docraptor.com/examples
*
* Doc Raptor http://docraptor.com
* Expected Behavior http://www.expectedbehavior.com
*/
<?php
$api_key = "YOUR_API_KEY_HERE";
$url = "https://docraptor.com/docs?user_credentials={$api_key}";
$document_content = "<table><tr><td>Cell</td></tr></table>";
$request = new HTTPRequest($url, HTTP_METH_POST);
$request->setPostFields(array('doc[document_content]' => $document_content, 'doc[document_type]' => 'xls', 'doc[name]' => 'my_doc.xls', 'doc[test]' => 'true'));
$request->send();
$file = fopen("my_excel_doc.xls", "w");
fwrite($file, $request->getResponseBody());
fclose($file);
?>