2016-09-19 6 views
0

私は外部ホストに接続することに決めましたが、動作しません。どのようにできるのか? これはexempleです:何が間違っている(私はGoogleのアドレスに私のurlを使用している場合、彼は仕事)..外部ホスト(ローカルホストではなく)に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(); 
     } 

が、私は私のURLを使用するときに動作しないのですか?

+0

何かエラーが発生しました – DKV

+0

何もしていません。ボタンをクリックすると彼は何もしません。 –

+0

マニフェストにintenetパーミッションを追加しました – DKV

答えて

1

reg_urlではなくlogin_urlURL url = new URL(reg_url)に使用する予定ですか?私はreg_urlが何か他のもので初期化されたと思います。

+0

omg、気晴らしのエラーを使用するために追加します。 Tnksの多く:D私は15ポイントを持っていないので、私はポイントを与えることはできませんD: –

関連する問題