GetResponse - HttpURLConnection

1

I'mtryingtogetagetResponsereturn.IcanseethereturnwithSystem.out.println,butIcannotgetthesamereturninsidetheapplication.

HttpURLConnectionconexao=(HttpURLConnection)url.openConnection();conexao.setDoOutput(true);BufferedReaderin=newBufferedReader(newInputStreamReader(conexao.getInputStream()));StringinputLine="";
             while ((inputLine = in.readLine()) != null)
                 System.out.println(inputLine);
             lblStatus.setText(inputLine);


             String respostaenvio = SomenteNumeros(inputLine);

             double resposta = Double.parseDouble(respostaenvio);

             if(resposta > 100000){
                 System.out.println("Enviado");
             }else{
                 System.out.println("Não Enviado");
             }
             in.close();
             conexao.disconnect();
            }

Can you help me figure out what's wrong?

I need the replyback information to determine whether or not an SMS was sent.

In the line System.out.println(inputLine); it prints exactly the code I need, but when I try to print this same code in JOptionPane , for example, it will not.

    
asked by anonymous 26.07.2016 / 14:16

1 answer

1

Look at this your while :

String inputLine = "";
while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);
lblStatus.setText(inputLine);

String respostaenvio = SomenteNumeros(lastLine);

What is the necessary condition to exit while ? This is when the line read, which is in inputLine is null . This means that after while is finalized, inputLine will always be < null , and that null will be placed in the label and passed to SomenteNumeros method. >

I think what you wanted is this:

String inputLine = "";
String lastLine = "";
while ((inputLine = in.readLine()) != null) {
    lastLine = inputLine;
    System.out.println(lastLine);
}
lblStatus.setText(lastLine);

String respostaenvio = SomenteNumeros(lastLine);

That is, I have a new variable lastLine that represents the last line read and valid , not just the last line read (which will always be null at the end).

    
26.07.2016 / 14:38