2016-07-15 4 views
0

私はポストメソッドとパラメータを使用してphp Webサービスを呼び出そうとしていますが、私はOutputStreamWriterで例外を取得していますwr = new OutputStreamWriter(conn.getOutputStream());この行は、私はデバッグで気づいたが、私はこのエラーを検索しているが、適切な解決策を得ていない、誰も私がこのエラーを解決するのを助けることができますか?前もって感謝します。どのようにJavaを解決するか.Io.IoException in android

String data = URLEncoder.encode("name", "UTF-8") 
       + "=" + URLEncoder.encode("wsd", "UTF-8"); 

     data += "&" + URLEncoder.encode("email", "UTF-8") + "=" 
       + URLEncoder.encode("asd", "UTF-8"); 

     data += "&" + URLEncoder.encode("user", "UTF-8") 
       + "=" + URLEncoder.encode("asd", "UTF-8"); 

     data += "&" + URLEncoder.encode("pass", "UTF-8") 
       + "=" + URLEncoder.encode("sad", "UTF-8"); 

     String text = ""; 
     BufferedReader reader=null; 
     try 
     { 

      // Defined URL where to send data 
      URL url = new URL("http://androidexample.com/media/webservice/httppost.php"); 

      // Send POST data request 

      URLConnection conn = url.openConnection(); 
      conn.setDoOutput(true); 
      OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
      wr.write(data); 
      wr.flush(); 

      // Get the server response 

      reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
      StringBuilder sb = new StringBuilder(); 
      String line = null; 

      // Read Server Response 
      while((line = reader.readLine()) != null) 
      { 
       // Append server response in string 
       sb.append(line + "\n"); 
      } 


      text = sb.toString(); 
     } 
     catch(Exception ex) 
     { 

     } 
     finally 
     { 
      try 
      { 

       reader.close(); 
      } 

      catch(Exception ex) {} 
     } 

     // Show response on activity 
     //content.setText(text ); 

    return text; 
    } 

答えて

1

パラメータを送信するには、この方法を試してください。

OutputStream output = new BufferedOutputStream(urlConnection.getOutputStream()); 
output.write(param.getBytes()); 
output.flush(); 
output.close(); 
+0

を私は同じエラーを取得しています。 –

+0

例外メッセージを投稿できますか? –

関連する問題