I have a GWT script which needs to get data from a PHP file kept on
the same server (Domain). Everything works fine on my local server
i.e. no SOP issues but when I transfer all the files to production
server I get getStatusCode() = 0 with empty response.
I have kept Both script mymodule.nocache.js and PHP files are in same
folder to avoid any issues with SOP:
http://mydomain.com/tools/gwt/mymodule.nocache.js ( and all the
associated files)
http://mydomain.com/tools/gwt/mylogoic.php
http://mydomain.com/tools/gwt/index.html
etc.
Following is my gwt code:
String url = "
http://mydomain.com/tools/gwt/
mylogic.php?q=";
url += inputTextBox.getText();
url = URL.encode(url);
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
url);
builder.setHeader("Content-Type","application/x-www-form-
urlencoded");
try {
Request request = builder.sendRequest(" ", new
RequestCallback() {
public void onError(Request request, Throwable exception) {
// Couldn't connect to server (could be timeout, SOP
violation, etc.)
}
public void onResponseReceived(Request request, Response
response) {
if (200 == response.getStatusCode()) {
outputTextBox.setText(response.getText());
Window.alert(""+response.getStatusCode());
} else {
errorLabel.setText("Status Text = " +
response.getStatusText());
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
}
PHP file:
<?php
$q = $_GET['q'];
$symbols = explode(' ', $q);
$in_val = $symbols[0];
echo $in_val;
?>
Also, if i directly access the PHP file it returns the correct
variable value.
i.e.
http://mydomain.com/tools/gwt/uconvert.php?q=100000
i get in return: 100000
I tried to debug using firebug and got following output:
GET
http://mydomain.com/tools/gwt/uconvert.php?q=100 200 OK 231ms
Parameter: q 100
Response Headers
Date Sun, 18 Sep 2011 13:42:42 GMT
Server Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.8e-fips-rhel5
mod_bwlimited/1.4
Cache-Control no-cache
Pragma no-cache
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/plain; charset=utf-8
Request Headers
Host
mydomain.com
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:6.0.2)
Gecko/20100101 Firefox/6.0.2
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Content-Type text/plain; charset=utf-8
Referer
http://www.mydomain.com/tools/gwt/index.html
Origin
http://www.mydomain.com
Please help.
Thanks
Ravi