Вопрос

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