Solved

How to make curl actually submit posted data

Posted on 2008-06-25
3
314 Views
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.
<?php
 
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
		curl_close($this->curl);
 
		return $this->getOutput();
	}
 
	private function getOutput() {
		print "HTTP code: $this->httpcode, Result: $this->result";
	}
}
 
// Use case login:
$curl = new instanceOfCurl('http://10.0.0.110/~mypath/dd/?page=Login', 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

0
Comment
Question by:rae_rae
3 Comments
 
LVL 3

Accepted Solution

by:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Error - Add Failed 12 94
I need an assist with a programming logic math question. 5 73
Advice in Xamarin 21 97
Calculate 10 hour work day for specific tasks 3 36
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Read about why it is more lucrative for an IT company to participate in government projects.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

828 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