One solution to this was posted in the PHP documentation comments: http://www.php.net/manual/en/function.curl-exec.php#80442
Code example:
$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); // ... $response = curl_exec($ch); // Then, after your curl_exec call: $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size);
Warning: As noted in the comments below, this may not be reliable when used with proxy servers or when handling certain types of redirects. @Geoffrey’s answer may handle these more reliably.
Related Posts:
- How to define the basic HTTP authentication using cURL correctly?
- How to define the basic HTTP authentication using cURL correctly?
- Setting Curl’s Timeout in PHP
- Is curl required?
- Should a 502 HTTP status code be used if a proxy receives no response at all?
- What is the difference between a URI, a URL and a URN?
- HTTP Status 504
- What is the difference between POST and GET? [duplicate]
- Do I need Content-Type: application/octet-stream for file download?
- Problem HTTP error 403 in Python 3 Web Scraping
- application/x-www-form-urlencoded or multipart/form-data?
- Problem HTTP error 403 in Python 3 Web Scraping
- application/x-www-form-urlencoded or multipart/form-data?
- Is 418 “I’m a teapot” really an HTTP response code?
- “Cannot GET /” with Connect on Node.js
- “CAUTION: provisional headers are shown” in Chrome debugger
- What’s the difference between a POST and a PUT HTTP REQUEST?
- How to do a PUT request with cURL?
- PHP + curl, HTTP POST sample code?
- How do I send a POST request with PHP?
- Why is it said that “HTTP is a stateless protocol”?
- What’s the difference between using application/csv vs text/csv? [duplicate]
- What are all the possible values for HTTP “Content-Type” header?
- What is the difference between PUT, POST and PATCH?
- What’s the difference between “Request Payload” vs “Form Data” as seen in Chrome dev tools Network tab
- Exception in thread “main” java.net.NoRouteToHostException: No route to host
- ndroid 8: Cleartext HTTP traffic not permitted
- How are parameters sent in an HTTP POST request?
- Why am I suddenly getting a “Blocked loading mixed active content” issue in Firefox?
- wget: unable to resolve host address `http’
- Are HTTP headers case-sensitive?
- When looking at the differences between X-Auth-Token vs Authorization headers, which is preferred?
- WordPress HTTP parameter pollution
- Does WordPress send data about your blog to WordPress.org or Automattic?
- Hiding WordPress REST API v2 endpoints from public viewing
- Does WordPress only support HTTP 1.1?
- HTTP request on localhost failing
- How can I use CURLOPT_USERPWD in wp_remote_post?
- How do I troubleshoot responses with WP HTTP API?
- The resource was preloaded using link preload but not used within a few seconds
- using wp_remote_get to retrieve own url on local host
- Using wp-cron in backpress – problems with wp_remote_post, fsockopen error
- Running index.php from command line & load balancer health checks
- Enable CORS in wordpress
- Change port of wordpress
- How to get value of custom http header?
- Several times request to load plugins when sending one request
- why is $_REQUESt[‘redirect_to’] empty?
- Get “HTTP/1.1 406 Not Acceptable” when accesing my website with Delphi Indy Control
- WordPress HTTP 500 Error “page isn’t working”
- Does WordPress perform better with curl installed?
- Get full page HTML for a non-public WordPress page
- What’s the point in having “www” in a URL?
- For what is the “.well-known”-folder?
- Human readable format for http headers with tcpdump
- How to make wireshark filter POST-requests only?
- Image file urls still point to http instead of https
- How do I install and use cURL on Windows?
- Possible reason for NGINX 499 error codes
- cURL to show response headers after submiting a file
- How to download HTTP directory with all files and sub-directories as they appear on the online files/folders list?
- cURL error 60: SSL certificate: unable to get local issuer certificate
- How do I make curl ignore the proxy?
- What exactly is cacert.pem for?
- PHP cURL custom headers
- How to remove rest api link: in http headers?
- How to receive HTTP POST in WP?
- cURL 28 error after switch from to brew php 7.2 on localhost
- Creating a post with the REST API, curl and oauth returning 401 error
- wp_remote_get() not retrieving pages properly
- Setting Last Modified HTTP Header on static Home Page
- Redirect from https to http or from http to https? [closed]
- Retrieving Google Plus share count with wp_remote_post
- Disabling the X-Redirect-By response header
- problem using WP_Http with paypal nvp api
- Why Better WP security plugin returns 418 I’m a Teapot “error”?
- Handling the response sent from a ruby on rails application in wordpress
- Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
- Programmatic Login from 3rd Party site
- WordPress 502 | Header Upstream send too big
- WordPress from url get external source title
- Download file using cURL into wp-includes/uploads
- WordPress index.php seems to perform unwanted redirect 301
- Error: Can´t access facebook comment plugin admin page
- HTTP Error upload ( localhost )
- WP Refused to display ‘URL’ in a frame because it set ‘X-Frame-Options’ to ‘sameorigin’
- Why does WordPress uses HTTPS for JS, CSS on EC2
- After changing Site http to https, can’t access wp login page with a digitalocean hosting
- WP Rest Api GET method restriction on route, but POST method also works
- Modify wp headers on specific page
- Sending WordPress database information to cross domain the safe way?
- Run WordPress Plugin in the Specified time
- How to use the HTTP API (wp_remote_get) instead of cURL?
- How to list Apache enabled modules?
- How to test a HTTPS URL with a given IP address
- Difference between `curl -I` and `curl -X HEAD`
- How do high traffic sites service more than 65535 TCP connections?
- Best way to redirect all HTTP to HTTPS in IIS
- wp_remote_post vs curl to send data in WordPress plugin
- Development to production, how to move a development site from http + dev.example.com to a production site https + example.com?