hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Speirs <wspe...@apache.org>
Subject Re: How to get HttpResponse viewed in a JEditorPane?
Date Tue, 31 Jul 2012 23:23:56 GMT
My only suggestion is to read the contents of the response out to something
else like a file, this way you know HttpClient is working as expected.

I don't know enough about JEditorpane to help you with that... maybe you
need to call flush on it?

Bill-
On Jul 30, 2012 6:04 AM, "Fredrik Andersson" <fredand44@hotmail.com> wrote:

>
> Hell Guys!
>
> I have a goal to view the response from a HttpClient response in a
> JEditopane.
> If I just do like this in a Jeditorpane:
>
> setPage("http://www.nu")
> ...it works like a dream.
>
> But my app sends a form and I would like to view the result in a
> JEditorpane something like:
>
>  HttpPost httppost = new HttpPost( form.getAction() );
>  httppost.setEntity(entity);
>  HttpResponse httpResponse = httpclient.execute(httppost);
>  InputStreamReader inputStreamReader = new
> InputStreamReader(httpResponse.getEntity().getContent());
>  BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
>  StringBuffer lines = new StringBuffer(  );
>  String line = "";
>  while ( (line = bufferedReader.readLine()) != null)
>  {
>   lines.append(line);
>   lines.append('\n');
>  }
>  String html = lines.toString();
>
> In subclass of JEditorpane I have tried like:
>  setText( html );
> ...and also read from the InputStream.
>  try
>  {
>   InputStreamReader inputStreamReader = aObjectOfMy.getInputStreamReader();
>   BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
>   synchronized(inputStreamReader)
>   {
>    read(bufferedReader, null);
>   }
>  }
>  catch (IOException e)
>  {
>   e.printStackTrace();
>   setText( "url: " + formResponse.getUrl() + "\n"+ e.getMessage() );
>  }
>
> But I never get it to be view like it should be, sometime noting at all is
> viewed and some times I get no images.
> I think you could try it agains any form out there. I have never managed
> to view any response properly.
> How ever I would like to say that I think the error is my way to use
> JEditorpane, rather then something is wrong in HttpClient API.
> So if any one have any suggestions how to get the result viewed nice in a
> editorpane, please let me know.
> Best regards
> Fredrik
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message