Home > Backend Development > PHP Tutorial > How to Add Custom Headers to cURL Requests in PHP?

How to Add Custom Headers to cURL Requests in PHP?

DDD
Release: 2024-12-02 21:54:10
Original
250 people have browsed it

How to Add Custom Headers to cURL Requests in PHP?

Customizing Headers in cURL PHP Requests

In certain situations, modifying request headers becomes necessary, especially when emulating specific communication protocols. This article demonstrates how to add custom headers to cURL HTTP requests in PHP.

Solution:

To add custom headers to a cURL request, use the CURLOPT_HTTPHEADER option. This option accepts an array of header lines. For example, to set the headers mentioned in the question:

$ch = curl_init();

$headers = [
    'X-Apple-Tz: 0',
    'X-Apple-Store-Front: 143444,12'
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Copy after login

Once the headers are set, the request can be executed using curl_exec().

Reference:

For detailed information on this option, refer to the PHP manual: https://www.php.net/manual/en/function.curl-setopt.php

The above is the detailed content of How to Add Custom Headers to cURL Requests in PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template