Page 1 of 1

curl problem, sending xml and values in the same post reques

Posted: Sat Oct 11, 2008 12:41 pm
by allanre
Hello!

Im new to cURL and i have problem understanding it. I'm trying to make a post request to remote server using curl.
The data, what im sending is a content of a xml and other values. But the expected result is all wrong (wrong - indicates to incorrect input data). Im pretty sure that the data Im trying to send is correct (maybe curl just translates xml incorrectly or something).
I made a little html test form and tested it out (Works, im getting the result im expecting).

Help needed. :mrgreen:

Here is the code:

Code: Select all

 
<?php
define('URL_CLASS',http://www.domain.com/XML.asp?');
define('XML_CLASS', 'Name=Value1&Lastname=value2&XML=<?xml version="1.0" encoding="Windows-1257" ?><field>Value12</field>');
 
$ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, URL_CLASS);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, XML_CLASS);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $data=curl_exec($ch);
 curl_close ($ch);
 
echo $data;
?>
 

Re: curl problem, sending xml and values in the same post reques

Posted: Sun Oct 12, 2008 1:21 pm
by allanre
Help?

Re: curl problem, sending xml and values in the same post reques

Posted: Sun Oct 12, 2008 9:31 pm
by omika
Try taking out $ch as per below

Code: Select all

$data = curl_exec();

Re: curl problem, sending xml and values in the same post reques

Posted: Mon Oct 13, 2008 11:52 am
by allanre
nope, that wont solve the problem, instead of wrong data, now im getting a php warning which is reasonable as well... cause no handle is executed... :roll:
Any more ideas?

Ill specify the conditions... lets say

Post request in html

1 field: text (Goes a username)
2 field: text (Goes a password)
3 field: text (Goes a xml)
4 hidden field (some value)
5 hidden field (some value)

A submit button...

How this form should be presented to curl...

Re: curl problem, sending xml and values in the same post reques

Posted: Thu Oct 16, 2008 10:20 am
by allanre
If someone comes across with the same problem, i found the solution, there was problem with input data

I let the php scan the input data before cUrling

like this:
$fields = array(
'Field1' => 'VALUE1',
'Field2' => 'VALUE2',
'Field3' => 'VALUE3',
'XML' => '<?xml version="1.0" encoding="Windows-1257" ?><tag1>ValueOfTag1</tag1>'
);

$POST = http_build_query($fields);


Great success :mrgreen: