Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unset curl CURLOPT_POSTFIELDS

Tags:

php

curl

libcurl

I have an PHP class which is used to POST some data to a server, and GET some data back using the same open connection. The problem is that this code will try to POST data from 1st request, in the 2nd request...

curl_setopt(self::$ecurl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt(self::$ecurl, CURLOPT_POSTFIELDS, $data);
$request=curl_exec(self::$ecurl);
curl_setopt(self::$ecurl, CURLOPT_CUSTOMREQUEST, "GET");
$request=curl_exec(self::$ecurl);

So i need the way to unset CURLOPT_POSTFIELDS. I tried to use curl_setopt(self::$ecurl, CURLOPT_POSTFIELDS, null);, but anyway curl send Posting 0 bytes... in request's header.

Also please note, that i need to use exactly the same connection, so I can't create another connection via curl_init.

like image 645
user3742227 Avatar asked Sep 30 '22 13:09

user3742227


1 Answers

Set the CURLOPT_HTTPGET to true prior to the last request.

From PHP.net:

CURLOPT_HTTPGET

TRUE to reset the HTTP request method to GET. Since GET is the default, this is only necessary if the request method has been changed.

like image 73
Pred Avatar answered Oct 04 '22 19:10

Pred