2017-01-13 8 views
-1

httpUrlConnectionでGETメソッドを使用してパラメータを送信する方法を教えてください。 このコードを使用していますが、どのメソッドを使用してパラメータを送信する必要があるかわかりません。AndroidのHttpUrlConnectionでGETメソッドを使用してparamsを送信する方法

ここで

is = connection.getInputStream();に例外をスロー FileNotFoundException

そのコード..です

//is this line is correct? 
    url = new URL(u + "?" + getQuery(params)); 
        Log.v("testing", url.toString()); 

        connection = (HttpURLConnection) url.openConnection(); 
        connection.setReadTimeout(10000); 
        connection.setConnectTimeout(15000); 
        connection.setRequestMethod("GET"); 
        connection.setDoInput(true); 
        connection.setDoOutput(true); 

        os = connection.getOutputStream(); 
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os)); 
        //bw.write(getQuery(params)); 
        bw.flush(); 
        bw.close(); 
        os.close(); 

        connection.connect(); 

        is = connection.getInputStream(); 
        String line = ""; 
        BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
        StringBuilder sb = new StringBuilder(); 
        while ((line = br.readLine()) != null){ 
         sb.append(line); 
        } 
+1

"u +"? " + getQuery(params) 'です。それは十分です。それはあなたがしなければならないすべてのことです。ライターのものを削除します。そして出力を約束しないでください。出力ストリームを混乱させないでください。 – greenapps

答えて

0

私は解決策を持って...ちょうどその

012のように...コードからの出力のものを削除します
url = new URL(u + "?" + getQuery(params)); 
       Log.v("testing", url.toString()); 

       connection = (HttpURLConnection) url.openConnection(); 
       connection.setReadTimeout(10000); 
       connection.setConnectTimeout(15000); 
       connection.setRequestMethod("GET"); 
       connection.setDoInput(true); 

//code removed from here 

       connection.connect(); 

       is = connection.getInputStream(); 
       String line = ""; 
       BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
       StringBuilder sb = new StringBuilder(); 
       while ((line = br.readLine()) != null){ 
        sb.append(line); 
       } 
+0

'私は解決策を得ました。コミュニケーションの奇妙な方法。あなたは私のコメントにも反応していません。あなたは私のコメントだけを確認してください。自分自身で完全な回答を投稿していない。 – greenapps

+0

コメントで投票オプションを見つけようとしましたが、投稿した理由が見つかりませんでした – Asad

関連する問題