本文整理汇总了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);
?>