I have an url which is redirecting:

http://www.accessdata.fda.gov/Scripts/cder/DrugsatFDA/index.cfm?fuseaction=Reports.SetReport&rptname=1&reportSelectDate=12%2F2009&ta=Submits

org.apache.http.client.HttpClient can follow the redirect without any
problem and get the content.
However URLFetchService has problems following the redirects,
java.io.IOException: Could not fetch URL.

Clearly the implementations are different, but I wonder how I can get
the URLFetchService to also read in that url. Could this be a bug? If
I ask HttpClient not to follow the redirect, it comes back with
"temporarily moved", which I believe is HTTP Error 302.

Any help would be very kind.

The code using the URLFetchService:

URL url = new URL(urlStr);
URLFetchService urlFetchService =
URLFetchServiceFactory.getURLFetchService();
HTTPRequest httpRequest = new HTTPRequest(url,
HTTPMethod.GET,followRedirects());
HTTPResponse response = urlFetchService.fetch(httpRequest);

The code using HTTPClient

String url = "http://www.accessdata.fda.gov/Scripts/cder/DrugsatFDA/
index.cfm?
fuseaction=Reports.SetReport&rptname=1&reportSelectDate=12%2F2009&ta=Submits";
HttpClient httpclient = new DefaultHttpClient
();
httpclient.getParams().setBooleanParameter
(
                "http.protocol.handle-redirects",
true);
HttpGet httpGet = new HttpGet
(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler
();
String
responseBody;
try
{
responseBody = httpclient.execute(httpGet,
responseHandler);
        System.out.println
(responseBody);
} catch (ClientProtocolException e)
{
e.printStackTrace
();
} catch (IOException e)
{
e.printStackTrace
();
}

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to