Empty response from server using RequestBuilder getStatusCode() = 0

374 views
Skip to first unread message

RShekhar

unread,
Sep 18, 2011, 9:49:59 AM9/18/11
to Google Web Toolkit
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

Thomas Broyer

unread,
Sep 18, 2011, 12:41:28 PM9/18/11
to google-we...@googlegroups.com

On Sunday, September 18, 2011 3:49:59 PM UTC+2, RShekhar wrote:
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.
[…] 
Request Headers 
Host mydomain.com
[…] 
www.mydomain.com is not the same as mydomain.com; it is a SOP issue. 

RShekhar

unread,
Sep 18, 2011, 5:15:56 PM9/18/11
to Google Web Toolkit
Thanks Thomas.

Finally I fixed this issue.

I changed the url from "http://mydomain.com/tools/gwt/mylogic.php?q="
to "/tools/gwt/mylogic.php?q=".


RS
> www.mydomain.comis not the same as mydomain.com; it *is* a SOP issue.
Reply all
Reply to author
Forward
0 new messages