What should I do to connect to Server from eclipse - Android?

前端 未结 3 1039
生来不讨喜
生来不讨喜 2021-01-17 06:48

Gurus, I am a lil lost on this topic. Here\'s a breakdown of what I\'m trying to do.

[User/Android Device] sends location info to a server -> [server]

[serv

3条回答
  •  悲哀的现实
    2021-01-17 06:58

    call the following method to connect to any url and read response data from it. What so ever the URL you will hit. Url will be of any php or asp or jsp page or in any server side scripting language. The following method has nothing do with it. what so ever the url page will return that will be entered in your Log records. check Log cat for read result

     private void connectToServerAndReadData()
    {
         HttpURLConnection conn;
         boolean result = false;
    
             try{
                 // Enter any URL here you want to connect
                 URL url = new URL("http://php1.funnymedialinks.com/scribd/rcheck.php");
    
                // Open a HTTP connection to the URL
    
                 conn = (HttpURLConnection) url.openConnection();
                // conn.connect();
                  BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                  String line ;
    
    
    
                  while ((line = rd.readLine()) != null) {
    
                           Log.v("Readed Data from Server ","data- "+line);
    
                  }
    
    
    
                rd.close();
    
    
             }catch(MalformedURLException e){
    
                     e.printStackTrace();
             }
             catch(IOException e){
                     e.printStackTrace();               
             }
            catch(Exception e){
                     e.printStackTrace();           
             }
    
    
    
    
    
    }
    

提交回复
热议问题