PDA

View Full Version : Calling RESTful webservice



lilford.immanuel
28 Feb 2011, 3:51 AM
I am sure this is already in the forum.. I am just not able to find a solution yet..:(

I am trying to call a RESTful webservice across domain. I keep getting an error code.:(

I would be greatful if somebody can point me in the right direction.:)

If NOT across domain, atleast within the same domain would be helpful...

The following code does not seem to work...:((



Ext.Ajax.request({
url: 'http://<URL>/services/businessunitcombo',
waitMsg: "Sending Request...",
method: 'POST',
success: function(response, opts){alert('Must have been 2xx http status code');},
failure: function(response, opts){alert('Must have been 4xx or a 5xx http status code:' + response.status);}
});

joseeight
28 Feb 2011, 3:04 PM
You can't make an AJAX call cross domain, you must set up a proxy to do that. Here is what I used, got it a long time ago to solve the problem.



<?php
// Set content type here
header('Content-type: text/xml');

//Request URL
$requestURL = "URLofSERVICE" . $_SERVER['QUERY_STRING'];

//Getting data from URL requested
$handle = fopen($requestURL, "r");

//MAGIC!!!
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>


You call this page on the same server with the parameters you need to send to the regular service. It will return the same data you would get as making the same direct call.

lilford.immanuel
1 Mar 2011, 2:34 AM
Thank you Jose.. Will try this out... :)

lilford.immanuel
24 Mar 2011, 10:52 PM
I got it working by calling a servlet which I am comfy with.. Works like a charm...

Donna head or tail of PHP :(

Thanks a bunch mate :)