This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Can't access aspx page from Apache HTTPClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Can Watch "Can New topic

Can't access aspx page from Apache HTTPClient

Rahat Syed

Joined: Dec 03, 2008
Posts: 1

I want to access and login to website. But when I try to access this page, it redirects me to error page and ask to download IE browser. Can anybody help me? Follwoing is the code.

DefaultHttpClient httpclient = new DefaultHttpClient();

HttpGet httpget = new HttpGet("");

HttpResponse response = null;

response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
InputStream instream = entity.getContent();

BufferedReader reader = new BufferedReader(
new InputStreamReader(instream));

while((strLine = reader.readLine()) != null){
strPage += strLine;
//pdfFiles = getPDF(strPage);

Joe Ess

Joined: Oct 29, 2001
Posts: 9150

It is probably checking the user agent header. Try something like this:
Set the User-Agent request header to masquerade HttpClient as a popular browser such as IE or Firefox. Certain web sites are optimized to work with just one or a number of specific browser applications. These sites frequently reject requests originating from user agents they do not recognize. For example, setting the User-Agent request header to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) would deceive the target server into believing that the request was issues by Microsoft Internet Explorer 6.0 on Windows 2000.

HttpClient Trouble Shooting
[ December 03, 2008: Message edited by: Joe Ess ]

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Can't access aspx page from Apache HTTPClient
It's not a secret anymore!