How to make curl actually submit posted data

Posted on 2008-06-25
Last Modified: 2013-11-25
I am curious how I can make my $curl request actually submit the data it is posting. I need to make curl return an HTTP code of 202 intead of 200? In other words, I want my curl object to actually complete the POST by submitting the form.

I have attached my code.

class instanceOfCurl


	public function __construct($url, $params) {

		if (empty($url) or empty($params)) {

			return FALSE;


		$this->url = $url;

		$this->params = $params;

		// Set the user browser

		$this->user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";

		// Instantiate curl

		$this->curl = curl_init();

		// Allow redirect

		curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);

		// We are posting to the page

		curl_setopt($this->curl, CURLOPT_POST,1);

		// Build a query string to append to the URL

		$arguements = http_build_query($this->params);

		curl_setopt($this->curl, CURLOPT_POSTFIELDS,$arguements);

		// Don't use a cached version of the URL

		curl_setopt($this->curl, CURLOPT_FRESH_CONNECT, 1);

		// Set the URL we are posting to

		curl_setopt($this->curl, CURLOPT_URL,$this->url);

		// Get the header only

		curl_setopt($this->curl, CURLOPT_HEADER, 1);

		curl_setopt($this->curl, CURLOPT_NOBODY, 1);

		// Set the user browser

		curl_setopt($this->curl, CURLOPT_USERAGENT, $this->user_agent);

		// Set the return transfer as string

		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

		// Execute the request

		$this->result = curl_exec($this->curl);

		// Check if the request was not sent

		if (!$this->result) {

			return FALSE;


		// Get the HTTP code

		$this->httpcode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);

		// Close out the object


		return $this->getOutput();


	private function getOutput() {

		print "HTTP code: $this->httpcode, Result: $this->result";



// Use case login:

$curl = new instanceOfCurl('', array(

	'page' => 'Login',

	'last_class' => 'ChooseSite',

	'login_username' => 'my_username',

	'login_password' => 'my_password',

	'login_db' => 'my_database'


// Look into framework errors


Open in new window

Question by:rae_rae

Accepted Solution

rae_rae earned 0 total points
ID: 21904879
please accept this as my request to close this question. It is clear it cannot be answered. Thanks.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Communication between departments might not happen in two different languages, but they do exist in two different worlds. With different targets and performance goals the same phrase often means something completely different to each party. Learn ho…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now