post variable contents using cURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

post variable contents using cURL

Post by Clukey »

How do I post the contents of a variable using cURL and HTTPS POST? Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

just like you would a get variable, except instead of in the URL you set it via curl_setopt()

example: foo=bar
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

Unfortunately, I'm quite new to php, so I don't know how to do that either. Also, I'd like the post it to "https://testefsnet.concordebiz.com/efsnet.dll". Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I happend to see this link today:

http://www.phpit.net/article/using-curl-php/
(#10850)
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here's the code I have. Could you tell me whats wrong? Thanks.

Code: Select all

<?php 
function test(){   
	$url = "https://www.testefsnet.concordebiz.com/efsnet.dll";
	$params = "<Request StoreID=\"xxxxxxxx\" StoreKey=\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"
	ApplicationID=\"Test App\">
	<SystemCheck />
	</Request>";
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	$output = curl_exec ($ch);
	curl_close ($ch);
}
?>
<html>
<head>
<title>Test EFSNet Payment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="<?php test(); ?>">
<input type="submit" name="Submit" value="Test">
</form>
<?php echo $output; ?>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$params should be passed through rawurlencode() and be given a variable name to associate the value you already have with it like the example I posted already.
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

I tried the rawurlencode but it didn't change anything. Below is the code I have now, but I'm getting an error that says:

"ResponseCode=1032&ResultCode=999&ResultMessage=INVALID+CREDENTIALS"

What does this mean? Thanks

Code: Select all

<?php
$url = "https://testefsnet.concordebiz.com/efsnet.dll";
$params = "<Request StoreID=\"xxxxx\" StoreKey=\"xxxxxxxxxxxxxxxxx\" ApplicationID=\"Test App\"><SystemCheck /></Request>";
$user_agent = $_SERVER['HTTP_USER_AGENT']." via testpostvars.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
?>
<html>
<head>
<title>Test EFSNet Payment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $output; ?>
</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ResponseCode 1032, ResultCode 999 and ResultMessage INVALID CREDENTIALS. Seems pretty straight forward to me.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Yes, but are the credentials wrong or the submissions bad. Usually these thing, if they take POST data, want something like:

Code: Select all

$params = "myXML=<?xml version=\"1.0\" encoding=\"UTF-8\"?><Request StoreID=\"xxxxx\" StoreKey=\"xxxxxxxxxxxxxxxxx\" ApplicationID=\"Test App\"><SystemCheck /></Request>";
I assume that there is documentation for this thing?
(#10850)
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

I contacted the people who would know, and they said that the "https://testefsnet.concordebiz.com/efsnet.dll" page was never hit, so I assume it's not a problem with the $params. And I copied the $params code directly from an example in the documentation (I just changed the values).
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Not sure what "never hit means? When I go to that URL is says:

Code: Select all

ResponseCode=1030&ResultCode=999&ResultMessage=INVALID+REQUEST
Which makes sense. What have you tried? Have you just tried to pass it on the command line or via a test form? What exactly does the example in the manual say?
(#10850)
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

What I mean by never hit is that a request was never made to that page. I've only tried it on the command line, and I don't have any other credentials to try, and the example in the manual is only an example of the xml formatting so it doesn't offer any help for the php.
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

Hey, I got it working, I just had to add this line:

Code: Select all

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
Thanks for the help.
Post Reply