Skip to content

curl - fail-with-body support #11090

@rbro

Description

@rbro

Description

In cURL 7.76.0, a new option --fail-with-body was added:

https://daniel.haxx.se/blog/2021/02/11/curl-fail-with-body

Would it be possible to implement similar functionality in PHP's curl library?

I posted the below in Stack Overflow in 2021:

https://stackoverflow.com/questions/68246166/how-to-retrieve-curl-response-on-error-in-php

As I wrote in the post, I'm looking to:

  • on success, have the http response pass directly to the user's browser
  • but on error such as a http 500 error, get the http response body into a variable in PHP

I don't want to use CURLOPT_RETURNTRANSFER because on success, the PDF file returned is large and it would be inefficient to first save the file to a PHP string or a temp file, only to just echo it to the user's browser.

What I'm looking for is an option called CURLOPT_RETURNTRANSFERONERROR, where the response data is only returned on a http error.

Thank you for your help.

Ryan

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions