Getting response status code 0 in SmartGWT webservice call using json
Posted
by
Girish
on Stack Overflow
See other posts from Stack Overflow
or by Girish
Published on 2012-06-09T10:34:19Z
Indexed on
2012/06/09
10:40 UTC
Read the original article
Hit count: 242
smartgwt
I have developed application using SmartGWT, now i need to call webservice using json to another application which is deployed in another server for submitting username and password. When i make a request with url and POST method, getting the response status code as 0 and response text as blank.
Here is my code,
public void sendRequest() throws Exception {
// Get login json data to be sent to server.
String strData = createLoginReqPacket();
String url = "some url";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
builder.setHeader("Content-Type", "application/json");
builder.setHeader("Content-Length", strData.length() + "");
Request response = builder.sendRequest(strData, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
int statusCode = response.getStatusCode();
System.out.println("Response code ----"+response.getStatusCode()+"");
if (statusCode == Response.SC_OK) {
String responseBody = response.getText();
System.out.println("Respose :" + responseBody);
// do something with the response
} else {
GWT.log("Response error at server side ----",null);
// do in case of server error
}
}// end of method.
@Override
public void onError(Request request, Throwable exception) {
GWT.log("**** Error in service call ******",null);
}// end of method.
});
builder.send();
}// end of send request.
Please anybody knows the solution?? Give some reference code or links for this.
Thanks.
© Stack Overflow or respective owner