Page 1 of 1

post variable contents using cURL

Posted: Mon Apr 24, 2006 4:34 pm
by Clukey
How do I post the contents of a variable using cURL and HTTPS POST? Thanks.

Posted: Mon Apr 24, 2006 4:39 pm
by feyd
just like you would a get variable, except instead of in the URL you set it via curl_setopt()

example: foo=bar

Posted: Mon Apr 24, 2006 4:46 pm
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

Posted: Mon Apr 24, 2006 5:27 pm
by Christopher
I happend to see this link today:

http://www.phpit.net/article/using-curl-php/

Posted: Mon Apr 24, 2006 5:53 pm
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]

Posted: Mon Apr 24, 2006 7:19 pm
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.

Posted: Tue Apr 25, 2006 2:19 pm
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>

Posted: Tue Apr 25, 2006 2:29 pm
by feyd
ResponseCode 1032, ResultCode 999 and ResultMessage INVALID CREDENTIALS. Seems pretty straight forward to me.

Posted: Tue Apr 25, 2006 2:39 pm
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?

Posted: Tue Apr 25, 2006 2:39 pm
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).

Posted: Tue Apr 25, 2006 2:48 pm
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?

Posted: Tue Apr 25, 2006 2:56 pm
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.

Posted: Tue Apr 25, 2006 4:12 pm
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.