CodeIgniter Forums

Full Version: How to POST XML data in codeigniter?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]wahyusumartha[/eluser]
hello..
i have a problem while posting xml data to a url .....
could someone give me an example how to posting xml????

El Forum

[eluser]Udi[/eluser]
Why you need to post XML data with URL??
What are you trying to do?

El Forum

[eluser]wahyusumartha[/eluser]
i want to develop web service client with codeigniter.. so i have to post data with xml format...

for example :
i want to post this xml :
<customer>
<firstname>wahyu</firstname>
<lastname>sumartha</lastname>
</customer>

xml data above would be post to url (http://example.com:9090/resource/customer/add)

could u help me how to do it ???

El Forum

[eluser]Udi[/eluser]
You can't post XML data to url,
URL grabs XML data or prints it.

Is there any way that [http://example.com:9090/resource/customer/add] will grab the given XML?

El Forum

[eluser]wahyusumartha[/eluser]
Really ????
this url[http://example.com:9090/resource/customer/add] consumes xml data..
so, i have to post xml ...
i think we can post xml data.. because i have been developing desktop application with that web service and worked properly

El Forum

[eluser]Udi[/eluser]
Maybe you send it with regular POST and Form and then it builds the XML by itself.

El Forum

[eluser]wahyusumartha[/eluser]
i have been solved the problem with using curl to post xml data
Thanks Wink

El Forum

[eluser]Udi[/eluser]
You mind sharing the code?
I'm trying to understand what you did and meant exactly.

El Forum

[eluser]wahyusumartha[/eluser]
okay.. i will share the code Smile..
i want to post xml to web service server..

so i write controller like this :

function add_customer() {

$post = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n\n";
$post .= "<customer>\n";
$post .= "<firstname>sinichi</firstname>\n";
$post .= "<lastname>kudo</lastname>\n";
$post .= "</customer>\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"http://localhost:9090/TestRestful/resources/customersservice/add");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$res = curl_exec($ch);
curl_close ($ch);
echo $res;
}

controller above have a function to post xml data to web service server using curl Smile..
are you understand my problem previously now ? Smile