Android (Java) Simple Send and receive with Server - Fast Setup Challenge

后端 未结 4 1862
借酒劲吻你
借酒劲吻你 2020-11-29 20:30

I\'m writing an Android App and I\'m looking for the fastest (In terms of setup) way for me to send data to a server and receive information back on request.

We\'re

相关标签:
4条回答
  • 2020-11-29 21:06
    private void sendData(ProfileVO pvo) {
    
        Log.i(getClass().getSimpleName(), "send  task - start");
    
        HttpParams p=new BasicHttpParams();
        p.setParameter("name", pvo.getName());
    
        //Instantiate an HttpClient
        HttpClient client = new DefaultHttpClient(p);
    
        //Instantiate a GET HTTP method
        try {
            HttpResponse response=client.execute(new HttpGet("http://www.itortv.com/android/sendName.php"));
            InputStream is=response.getEntity().getContent();
            //You can convert inputstream to a string with: http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.i(getClass().getSimpleName(), "send  task - end");
    }
    
    0 讨论(0)
  • 2020-11-29 21:13

    Check out WWW.viewstreet.com developing an Apache plugin specifically for android serverside development for Java programmers

    0 讨论(0)
  • 2020-11-29 21:16

    The easiest solution for you would be to use the apache http client to get and post JSON requests to a php server.

    The android already has a JSON builder/parser built-in, as does PHP5, so integration is trivial, and a lot easier than using its XML/Socket counterparts.

    If you want examples of how to do this the android side of things, here is a twitter API that basically communicates with twitter via their JSON rest API.

    0 讨论(0)
  • 2020-11-29 21:22

    http://java.sun.com/docs/books/tutorial/networking/sockets/

    This is a good background tutorial to Java socket communication.

    0 讨论(0)
提交回复
热议问题