문제

So I made a little program and it sends a post method to a website and then prints out the response, can I show the response in a web browser?

HttpResponse response = client.execute(post);

      BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

      String line = "";
      while ((line = rd.readLine()) != null) {
        System.out.println(line);
        if (line.startsWith("Auth=")) {
          String key = line.substring(5);
          // Do something with the key
        }

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

That prints the whole page out for me in the debugger, can I display it in the browser instead?

I am using the HttpClient from apache.

Is it possible to somehow convert the response to a URI and then use java.awt.Desktop.getDesktop().browse(response);

도움이 되었습니까?

해결책

In order to display your response in a browser, you need to call your Servlet from a web client, and not from a java client. If your request is an HTTP GET request, you can just call it by typing the URL in the browser. Otherwise you need an HTML form that will access your Servlet.

다른 팁

You could write the response out to a file, and then open that file in the browser.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top