mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Added form_params option to CURLRequest.
This commit is contained in:
parent
8ba805550e
commit
5c5b60a2f4
@ -306,6 +306,8 @@ class CURLRequest extends Request
|
||||
$curl_options[CURLOPT_RETURNTRANSFER] = true;
|
||||
$curl_options[CURLOPT_HEADER] = true;
|
||||
$curl_options[CURLOPT_FRESH_CONNECT] = true;
|
||||
// Disable @file uploads in post data.
|
||||
$curl_options[CURLOPT_SAFE_UPLOAD] = true;
|
||||
|
||||
$curl_options = $this->setCURLOptions($curl_options, $this->config);
|
||||
$curl_options = $this->applyMethod($method, $curl_options);
|
||||
@ -557,6 +559,17 @@ class CURLRequest extends Request
|
||||
// Connection Timeout
|
||||
$curl_options[CURLOPT_CONNECTTIMEOUT_MS] = (float)$config['connect_timeout'] * 1000;
|
||||
|
||||
// Post Data - application/x-www-form-urlencoded
|
||||
if (! empty($config['form_params']) && is_array($config['form_params']))
|
||||
{
|
||||
$curl_options[CURLOPT_POSTFIELDS] = http_build_query($config['form_params']);
|
||||
|
||||
if (empty($this->header('Content-Type')))
|
||||
{
|
||||
$this->setHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
}
|
||||
|
||||
return $curl_options;
|
||||
}
|
||||
|
||||
|
@ -251,6 +251,24 @@ Allows you to pause a number of milliseconds before sending the request.::
|
||||
// Delay for 2 seconds
|
||||
$response->request('GET', 'http://example.com', ['delay' => 2000]);
|
||||
|
||||
form_params
|
||||
===========
|
||||
|
||||
You can send form data in an application/x-www-form-urlencoded POST request by passing an associative array in
|
||||
the ``form_params`` option. This will set the ``Content-Type`` header to ``application/x-www-form-urlencoded``
|
||||
if it's not already set.::
|
||||
|
||||
$client->request('POST', '/post', [
|
||||
'form_params' => [
|
||||
'foo' => 'bar',
|
||||
'baz' => ['hi', 'there']
|
||||
]
|
||||
]);
|
||||
|
||||
.. :note:: ``form_params`` cannot be used with the ``multipart`` option. You will need to use one or the other.
|
||||
Use ``form_params`` for ``application/x-www-form-urlencoded`` request, and ``multipart`` for ``multipart/form-data``
|
||||
requests.
|
||||
|
||||
headers
|
||||
=======
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user