2016-09-19 66 views
0

我决定连接到外部主机我的应用程序,但不工作。我能怎么做? 这是个例:如何在外部主机(不是本地主机)上连接Android

String login_url = "http://***.**.**.**/fileman/**/register.php"; 
    // String login_url = "http://10.0.2.2/code/register.php"; 

    String method = params[0]; 

    if (method.equals("register")) { 


     String name = params[1]; 
     String user_name = params[2]; 
     String user_pass = params[3]; 

     try { 
      URL url = new URL(reg_url); 
      HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); 
      httpURLConnection.setRequestMethod("POST"); 
      httpURLConnection.setDoOutput(true); 
      //httpURLConnection.setDoInput(true); 
      OutputStream OS = httpURLConnection.getOutputStream(); 
      BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8")); 
      String data = URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(name, "UTF-8") + "&" + 
        URLEncoder.encode("user_name", "UTF-8") + "=" + URLEncoder.encode(user_name, "UTF-8") + "&" + 
        URLEncoder.encode("user_pass", "UTF-8") + "=" + URLEncoder.encode(user_pass, "UTF-8"); 
      bufferedWriter.write(data); 
      bufferedWriter.flush(); 
      bufferedWriter.close(); 
      OS.close(); 
      InputStream IS = httpURLConnection.getInputStream(); 
      IS.close(); 
      //httpURLConnection.connect(); 
      httpURLConnection.disconnect(); 


      ritorno = "Registration Success..."; 
      return ritorno; 

     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

与本地主机的工作,但是当我使用我的网址不工作。(如果用我在谷歌ADRESS网址他工作)

有什么不好?

+0

ü没有得到任何错误 – DKV

+0

没有,他什么都不干。我需要点击按钮,当我点击他什么都不干。 –

+0

迪迪ü在清单 – DKV

回答

1

您是否应该在URL url = new URL(reg_url)中使用login_url而不是reg_url?我认为reg_url是用别的东西初始化的。

+0

omg,错误的分心。 Tnks很多:D我不能给你的观点,因为我没有15代表D: –