473,661 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Post method - Cookie Issue

freddieMaize
85 New Member
Hi everyone,

I'm trying to access a url from java (using java post method). The url is a login page. I then insert values (username and password) to it an try to post that page. Below is my code,

Expand|Select|Wrap|Line Numbers
  1.             PrintWriter out = new PrintWriter(new FileWriter("GSA Report Log.txt"));
  2.  
  3.             String ipAddress = "******";               //give the ipadress here
  4.             int portNo = 8000;                     //give the port number here
  5.  
  6.             String path = "";                    //give the path(url)
  7.             String data = "";                    //give the inpurt parameters
  8.             URL url = null;
  9.             URLConnection conn = null;
  10.             OutputStreamWriter wr = null;
  11.             BufferedReader rd = null;
  12.  
  13.             StringBuffer sbTopKeywords = new StringBuffer();
  14.             ArrayList list_TopKeywords = new ArrayList();
  15.  
  16. //Process 1 - Login to the Appliance
  17. //The Requested URL : https://ipAddress:portNo/EnterpriseController?actionType=reload&lastcmd=login
  18.             System.out.println("********************  Start of Porcess 1 ********************");
  19.             path = "/EnterpriseController";
  20.             data = "userName=" + URLEncoder.encode("******", "UTF-8") +
  21.                     "&password=" + URLEncoder.encode("****", "UTF-8");
  22.             url = new URL("http://" + ipAddress +":"+ portNo + path);
  23.             conn = url.openConnection();
  24.             conn.setDoOutput(true);
  25.             wr = new OutputStreamWriter(conn.getOutputStream());
  26.             wr.write(data);
  27. System.out.println(data);
  28. System.out.println(wr.toString());
  29.             wr.flush();
  30.             rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  31.             String line;
  32.             while ((line = rd.readLine()) != null) {
  33.                 System.out.println(line);
  34.             }
  35.             System.out.println("********************  End of Porcess 1 ********************");
  36.  
  37.             wr.close();
  38.             rd.close();
I get a error saying I need to enable cookie in my browser. But even after doing so it is still throwing me the same error. Below is the error message,
Expand|Select|Wrap|Line Numbers
  1. Access to this system requires that you allow cookies to be set on your computer.  Please enable cookies in your
  2. browser and hit reload twice. You can find your cookie settings under "Tool
  3. s -> Internet Options" for Internet Explorer and "Edit -> Preferences&
  4. quot; for Netscape.
Expand|Select|Wrap|Line Numbers
  1.             while ((line = rd.readLine()) != null) {
  2.                 System.out.println(line);
  3.             }
The print statement, i'm getting null

Any thoughts on this please do share. Thanks a lot :)

fREDDIE
Apr 2 '09 #1
2 6309
mschenkelberg
44 New Member
usually cookie checking is done using client side javascript, the site might be checking to see if you are a valid browser by checking the user-agent property and seeing if it is a known browser. I'm not sure though, but I know it is possible to "pretend" to be a valid browser like firefox by doing something like url.setRequestP roperty("User-Agent", "user agent string"); . Maybe look into this.

Max
Apr 15 '09 #2
pronerd
392 Recognized Expert Contributor
You will spend a huge amount of time trying to work out all the details of emulating a HTTP client your self. You would be a lot better of using one of the library's for this. Like HttpClient lib (http://hc.apache.org/httpclient-3.x/) from Apache.
Apr 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2577
by: Phil Powell | last post by:
URL: http://valsignalandet.com/cookiegrab.php?name=valIdentifier This page produces a cookie value and sends it back as HTML using PHP and Javascript to obtain it. This URL will be used as the value for a URLConnection object in a Java class to obtain the results of this page to get, of all things, a cookie value. Simply put: it's the ONLY way I know of where I can use Java to ultimately obtain a cookie since this is an application...
0
6803
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
1
47606
by: greg.knaddison | last post by:
Hi, I'm trying to use the httpclient within Jython (see http://jakarta.apache.org/commons/httpclient/ for more information on the httpclient). My Jython version is: Jython 2.1 on java1.4.2_04 (JIT: null) My Java version is:
3
3951
by: Amil | last post by:
Please don't repond to this if you are guessing or just don't know the answer. I'm trying to login to a backend system running Java/Tomcat. I create a HttpWebRequest with the login data and do a POST. This works fine. The HttpWebResponse content I get back is just javascript "window.location=xxx" (with normal html around it). The HttpWebResponse also contains a java session id cookie. Fine so far. I want to go to the new location...
1
9623
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
2
1378
by: Kevin Blount | last post by:
I have a situation where I think I'm calling a method too quickly, but I'm not sure a) how to prove that theory and b) slow it down if I'm right. Here's the code: CODEFILE.ASPX.CS public void updateCookie(string cookieName, string cookiePairName, string cookiePairValue) { if (Request.Cookies != null) { string currentCookie = Request.Cookies.Value; currentCookie += "&" + cookiePairName + "=" + cookiePairValue;
10
8631
by: TahseenTarafdar | last post by:
Hi, I am updating a Java servlet to store cookies. The class inherits from HttpServlet and overrides the "service" method. Within this method I have the following code to test cookie storing and retreival: public void service( HttpServletRequest req, HttpServletResponse res ) throws IOException { ...... Cookie cookies = req.getCookies(); if( cookies != null ) {
8
6073
by: inpuarg | last post by:
I 'm developing a c# (.net 2.0) windows forms application and in this application i want to connect to a java servlet page (HTTPS) (which is servlet 2.4 and which may be using Web Based SSO Sun Java System Access Manager but i 'm not sure), handle session management, get token, send data using post and get methods etc. I listened http traffic using Fiddler and sending the same messages from my application but browser based navigation is...
2
2692
by: Jay | last post by:
I have a web app running on the windows CE device. In one of the asp.net pages - it has javascript code. That seems to have a memory leak. When I run the web app - in about one hour, the app hangs. I looked at the memory and it seems to be full. I removed all the javascript code - and the app seems to be have no leaks. As soon as I include my javascript code - the memory consumption gradually increases. Whether I actually invoke the...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.