File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Can Watch "Can New topic
Author

Can't access aspx page from Apache HTTPClient

Rahat Syed
Greenhorn

Joined: Dec 03, 2008
Posts: 1
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

Joined: Oct 29, 2001
Posts: 8877
    
    8

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't access aspx page from Apache HTTPClient