开发者

Send/Receive requests. Android <> Server

I would like my application to send/receive requests from a LOCAL server, my laptop for instance. Can anyone provide me with the necessary steps I need to follow in order to understand how this can work with an Android application?

Here is an example. Let's assume my application wants to compute "1+1" however it doesn't know whether or not 1+1 is equal to 2. The only way to get around this issue is to send a request which is basically the algebraic expression(1+1) and the answer(equal to 2) to the server which will check the answer from a file that it has to read an开发者_JAVA百科d send back to the application a message stating whether or not the answer is correct.


I've been using Android Query to make http get/post requests and it works pretty good:



String url = "http://10.0.2.2/add/1/1";        
aq.ajax(url, JSONObject.class, new AjaxCallback() {

  @Override
  public void callback(String url, JSONObject json, AjaxStatus status) {

    if(json != null){                              
      //successful ajax call, show status code and json content
      Toast.makeText(aq.getContext(), "result: " + json.toString(), Toast.LENGTH_LONG).show();                    
    }else{                             
      //ajax error, show error code
      Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
     }
  }
});

You can also chose html/xml/byte as response type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜