• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't access aspx page from Apache HTTPClient

 
Rahat Syed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to access and login to https://alta.registries.gov.ab.ca/SpinII/Logon.aspx 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("https://alta.registries.gov.ab.ca/SpinII/Logon.aspx");

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;
}
System.out.println(strPage);
//pdfFiles = getPDF(strPage);
entity.consumeContent();

}
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic