aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes how to read content of a url that require login Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "how to read content of a url that require login" Watch "how to read content of a url that require login" New topic
Author

how to read content of a url that require login

li leon
Greenhorn

Joined: Oct 19, 2002
Posts: 1
how to read content of a url that require login
I want to use a java program to read content of a url,some codes are:
URLConnection srcUrl = new URL(srcFile).openConnection();;
DataInputStream datainput = new DataInputStream(srcUrl.getInputStream());
when read a common url,all is ok,but when read a page that require login,it show errors,for example,the error is :
"<b>Fatal error</b>: Call to undefined function: () in <b>D:\web\epubcn\discuz\header.php</b> on line <b>224</b><br />"
I think it relates to cookie problem,how can I solve this problem,thanks in advance.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 639
Originally posted by li leon:
how to read content of a url that require login.

When you make an HTTP connection to retrive some web page content , you use GET request metho of the HTTP protocol . So when it comes to some sort of authentication which requires a login interface , you would want to write to the URL first and then read the contents . So for writing to the URL you would have to change the request method from GET (default ) to POST by using the setRequestMethod("POST")the URLConnection class and would have use the outputstreams to write data that URl. Once you've finished writing ,start reding from it by using the input streams .Don't forget to close and flush the output streams .
hope this helps.
[ October 20, 2002: Message edited by: raghav mathur ]

Raghav.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to read content of a url that require login
 
Similar Threads
External WebpAge rendering
Redirect to the requested page failed using form-based authentication
Problem with JSPs in web application
servlet to bypass basic authentication
JWebPlus questions