private function makeRequestList(array $urls) { $request = array(); foreach ($urls as $url) { $request = new Request($url); $request->setOption(CURLOPT_RETURNTRANSFER, true); $requests[] = $request; } return $requests; }
public function __construct($url, $method = "GET", array $params = array()) { $method = strtoupper($method); $this->method = $method; if (!empty($params) && in_array($method, array("GET", "PUT", "DELETE"))) { $url .= '?' . http_build_query($params); } $this->setUrl($url)->setParams($params); parent::__construct($url); $this->setMethod($method); if (!empty($params) && in_array($method, array("POST", "PATCH"))) { $this->setOption(CURLOPT_POSTFIELDS, http_build_query($params, '', '&')); } $this->setOption(CURLOPT_RETURNTRANSFER, true); }
/** * Get the content returned by a Request managed by this object * * Analogous to curl_multi_getcontent * * @param Request $request The Request to get the results for * @return string */ public function getContent(Request $request) { return curl_multi_getcontent($request->getHandle()); }
/** * Populate the POSTFIELDS option * * @param CurlRequest $curl cURL request object * @param Request $request the Request object we're populating */ protected function setPostFields(CurlRequest $curl, HttpRequest $request) { $postfields = null; $content = $request->getContent(); if (!empty($content)) { $postfields = $content; $a = 1; } else { if (count($request->files)) { // Add files to postfields as curl resources foreach ($request->files->all() as $key => $file) { $file = $this->createCurlFile($file->getRealPath(), $file->getMimeType(), basename($file->getClientOriginalName())); $request->request->set($key, $file); } $postfields = $request->request->all(); // we need to manually set content-type $request->headers->set('Content-Type', "multipart/form-data"); $a = 2; } else { if (count($request->request)) { $postfields = http_build_query($request->request->all()); $a = 3; } else { return; } } } if (is_string($postfields)) { $curl->setOption(CURLOPT_POSTFIELDS, $postfields); $request->headers->set('content-length', strlen($postfields)); } else { $curl->setOption(CURLOPT_POSTFIELDS, $postfields); } }
public function testClone() { $request = new Request(); $clone = clone $request; $this->assertThat($request->getHandle(), $this->logicalNot($this->equalTo($clone->getHandle()))); }
/** * Populate the POSTFIELDS option * * @param CurlRequest $curl cURL request object * @param Request $request the Request object we're populating */ private function setPostFields(CurlRequest $curl, Request $request) { $postfields = null; $content = $request->getContent(); if (!empty($content)) { $postfields = $content; } else { if (count($request->request->all()) > 0) { $postfields = http_build_query($request->request->all()); } } $curl->setOption(CURLOPT_POSTFIELDS, $postfields); }