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

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
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

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

Post 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;
?>
 
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

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

Post by allanre »

Help?
User avatar
omika
Forum Newbie
Posts: 19
Joined: Sun Oct 12, 2008 2:00 pm
Location: New Zealand

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

Post by omika »

Try taking out $ch as per below

Code: Select all

$data = curl_exec();
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

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

Post 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...
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

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

Post 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:
Post Reply