On Mon, 2009-02-23 at 01:00 -0500, Suneet Shah wrote:
> Hello:
>
> I am new to HttpClient and am trying to develop some proxy functionality
> for my application. I am using the code below to load a url and then
> render it in the browser.
> However, all if a page has relative urls, they all point to by proxy
> application, and not the application where they actually live. The
> result is that all the links are broken and none of the images,
> stylesheets, etc are loaded.
>
> How can I get around this? Any help will be appreciated.
>
Your proxy should either handle those requests by retrieving content
from the origin server or by rewriting relative urls in the HTML content
to point at the origin server
Oleg
> Thanks
> Suneet
>
>
> // get the request url
> // this url goes through the proxy
> // ie. http//localhost/myapp
> String uri = getURI((HttpServletRequest)request);
>
> // example 1 - load the contents of the
> HttpMethod method = new GetMethod("http://myhost.com/myapp");
>
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> new DefaultHttpMethodRetryHandler(3, false));
> method.setFollowRedirects(true);
>
> // Execute the method.
> int statusCode = httpClient.executeMethod(method);
>
> System.out.println("status - " + statusCode);
>
> if (statusCode != HttpStatus.SC_OK) {
> System.err.println("Method failed: " +
> method.getStatusLine());
> }
>
>
> InputStream streamFromServer = method.getResponseBodyAsStream();
> PrintWriter pw = response.getWriter();
> DataInputStream inStream = new
> DataInputStream(streamFromServer);
> String inputLine;
>
> while ((inputLine = inStream.readLine()) != null) {
> pw.println(inputLine);
> }
> inStream.close();
> pw.flush();
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]