Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve curlrequest.rst #8041

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions user_guide_src/source/libraries/curlrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ cookie
======

This specifies the filename that CURL should use to read cookie values from, and
to save cookie values to. This is done using the CURL_COOKIEJAR and CURL_COOKIEFILE options.
to save cookie values to. This is done using the ``CURL_COOKIEJAR`` and ``CURL_COOKIEFILE`` options.
An example:

.. literalinclude:: curlrequest/021.php
Expand All @@ -223,8 +223,10 @@ debug
=====

When ``debug`` is passed and set to ``true``, this will enable additional debugging to echo to STDERR during the
script execution. This is done by passing CURLOPT_VERBOSE and echoing the output. So, when you're running a built-in
server via ``spark serve`` you will see the output in the console. Otherwise, the output will be written to
script execution.

This is done by passing ``CURLOPT_VERBOSE`` and echoing the output. So, when you're running a built-in
server via ``spark serve``, you will see the output in the console. Otherwise, the output will be written to
the server's error log.

.. literalinclude:: curlrequest/034.php
Expand Down Expand Up @@ -270,8 +272,11 @@ further headers arrays or calls to ``setHeader()``.
http_errors
===========

By default, CURLRequest will fail if the HTTP code returned is greater than or equal to 400. You can set
``http_errors`` to ``false`` to return the content instead:
By default, CURLRequest will throw ``HTTPException`` if the HTTP code returned is
greater than or equal to 400.

If you want to see the response body, you can set ``http_errors`` to ``false`` to
return the content instead:

.. literalinclude:: curlrequest/026.php

Expand Down
9 changes: 5 additions & 4 deletions user_guide_src/source/libraries/curlrequest/026.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

$client->request('GET', '/status/500');
// Will fail verbosely
// If the response code is 500, an HTTPException is thrown,
// and a detailed error report is displayed if in development mode.

$res = $client->request('GET', '/status/500', ['http_errors' => false]);
echo $res->getStatusCode();
// 500
$response = $client->request('GET', '/status/500', ['http_errors' => false]);
echo $response->getStatusCode(); // 500
echo $response->getBody(); // You can see the response body.