How to Send a Raw POST Request Using cURL in PHP
In PHP, cURL is a popular library for sending HTTP requests. This article will demonstrate how to use cURL to perform a RAW POST request, where the data is sent in unencoded form.
Creating the Request
To send a RAW POST request, start by initializing a cURL session using curl_init(). Then, configure the following options:
Specifying the Content Type
For a RAW POST request, it's important to specify the content type of the body. In this case, it's text/plain. To do this, use the CURLOPT_HTTPHEADER option with an array containing the following header:
'Content-Type: text/plain'
Sending the Request
Once the request is configured, use curl_exec($ch) to send it. The response will be stored in the variable $result.
Example Code
The following code snippet provides an example of a RAW POST request using cURL in PHP:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://url/url/url"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, "body goes here"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); $result = curl_exec($ch);
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3