2017-02-04 1 views
0

내 앱을 통해 Tomcat 서버에 액세스 할 수 없지만 내 모바일 브라우저에서 동일한 URL을 열 수 있습니다. 내 노트북과 모바일 모두 동일한 라우터에 연결되어 있습니다. 또한 댓글이 달린 URL은 앱을 통해 액세스 할 수 있습니다.Android : Android 앱을 통해 Tomcat 서버에 액세스 할 수 없습니다.

WebService에 :

@Path("/hello") 
public class FirstTest { 
@GET 
    @Produces(MediaType.TEXT_PLAIN) 
    public String sayPlainTextHello() { 
    return "Hello Jersey"; 
    } 

    // This method is called if XML is request 
    @GET 
    @Produces(MediaType.TEXT_XML) 
    public String sayXMLHello() { 
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>"; 
    } 

    // This method is called if HTML is request 
    @GET 
    @Produces(MediaType.TEXT_HTML) 
    public String sayHtmlHello() { 
    return "<html> " + "<title>" + "Hello Jersey" + "</title>" 
     + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> "; 
    } 

} 

MainActivity.java :

hit.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      new JSONClass().execute("http://192.168.0.100:8081/TrekServerTest2/rest/hello"); 
      //new JSONClass().execute("https://jsonparsingdemo-cec5b.firebaseapp.com/jsonData/moviesDemoItem.txt"); 
     } 
    }); 
} 


public class JSONClass extends AsyncTask<String, String, String>{ 

    @Override 
    protected String doInBackground(String... params) { 
     HttpURLConnection httpURLConnection = null; 
     BufferedReader reader = null; 
     try { 
      URL url = new URL(params[0]); 

      httpURLConnection = (HttpURLConnection) url.openConnection(); 

      httpURLConnection.connect(); 

      InputStream stream = httpURLConnection.getInputStream(); 
      reader = new BufferedReader(new InputStreamReader(stream)); 
      StringBuffer buffer = new StringBuffer(); 
      String line=""; 
      while((line=reader.readLine())!=null){ 
       buffer.append(line); 
      } 
      return buffer.toString(); 
     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
      return "wrongUrl"; 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return "connError"; 
     } 
     finally { 
      if(httpURLConnection!=null) 
       httpURLConnection.disconnect(); 
      try { 
       if(reader!=null) { 
        reader.close(); 
       } 
      } catch (IOException e) { 
       e.printStackTrace(); 
       return "closeError"; 
      } 
     } 

    } 

    @Override 
    protected void onPostExecute(String s) { 
     super.onPostExecute(s); 
     tv.setText(s); 

    } 
} 

로그 캣 :

 02-04 17:44:25.922 724-967/? E/WifiConfigStore: updateSavedNetworkHistory(): try "Logon broadband GP"WPA_PSK SSID="Logon broadband GP" Logon broadband GP [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] ajst=0 
02-04 17:44:25.922 724-967/? E/WifiConfigStore:   got known scan result 0c:d2:b5:51:82:c6 key : "Logon broadband GP"WPA_PSK num: 1 rssi=-65 freq=2417 
02-04 17:44:25.942 724-967/? E/WifiAutoJoinController: status: bssid=0c:d2:b5:51:82:c6 
                freq=2417 
                ssid=Logon broadband GP 
                id=9 
                mode=station 
                pairwise_cipher=CCMP 
                group_cipher=TKIP 
                key_mgmt=WPA2-PSK 
                wpa_state=COMPLETED 
                ip_address=192.168.0.104 
                p2p_device_address=02:0e:41:4c:1d:2b 
                address=00:0e:41:4c:1d:2b 
                uuid=c753c5e7-fbf6-58ae-b610-23d41c19c3e4 
02-04 17:44:25.948 724-967/? E/WifiAutoJoinController: attemptAutoJoin() num recent config 1 current="Logon broadband GP"WPA_PSK ---> suppNetId=9 
02-04 17:44:25.948 724-967/? E/WifiAutoJoinController: Done attemptAutoJoin status=0 
02-04 17:44:25.951 724-967/? E/WifiConfigStore: writeKnownNetworkHistory() num networks:15 needWrite=false 
02-04 17:44:26.059 724-967/? E/WifiStateMachine: ConnectedState (when=-2ms what=131155 arg1=29!CMD_RSSI_POLL 29 0 "Logon broadband GP" 0c:d2:b5:51:82:c6 rssi=-64 f=2417 sc=60 link=135 tx=0.0, 0.0, 0.0 rx=0.3 bcn=0 [on:0 tx:0 rx:0 period:1378] from screen [on:0 period:151781643] gl hn u24 rssi=-59 ag=0 hr ticks 0,0,399 ls-=0 [56,56,56,56,61] brc=0 lrc=0 
+0

logcat은 무엇을 말하고 있습니까? –

+0

은 "http : //192.168.0.100 : 8081' (누락 된"// ")이어야합니다. –

+0

실수로"i "를 복사하는 동안"// "을 넣은 후에도 작동하지 않습니다. 이 게시물을보고 아무것도 제안 할 수 있다면. 그게 도움이 될거야 .http : //stackoverflow.com/questions/41921738/android-cannot-call-java-web-service-through-app? noredirect = 1 # comment71026412_41921738 – ManishPrajapati

답변

0

내가 실수는 내 경우에 무엇을 발견 생각합니다. 항상 잘못된 IP 주소를 사용하고있는 것처럼 보입니다. ipconfig를 통해 얻은 ip는 노트북과 장치가 연결된 일반적인 라우터가 아닙니다. 내가 연결된 와이파이의 속성에서 IP를 사용하여 시도하고, 짜잔!!. 모든 노력에 감사드립니다.

관련 문제