dcsimg
HttpURLConnection,cookie,session and cache???
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   wu_haifeng
Posted On:   Wednesday, June 30, 2004 10:12 AM

Site www.xx.net has this header: ---Start of headers--- Date: Thu, 01 Jul 2004 09:39:04 GMT Server: Apache/2.0.43 (Unix) mod_jk2/2.0.0 Set-Cookie: txlUserID=0; Path=/ Content-Type: text/html; charset=GBK Content-Length: 0 Site www.xx.net has this header: ---Start of headers--- Date: Thu, 01 Jul 2004 09:39:04 GMT Server: Apache/2.0.43 (Unix) mod_jk2/2.0.0 Set-Cookie: txlUserID=3723313; Path=/ Content-Type: text/html; charset=GBK Content-Length: 0 Connection: close ---End of headers--- Then I use the code below to keep state betwen tow connection and get what i want: St   More>>

Site www.xx.net has this header:
---Start of headers---
Date: Thu, 01 Jul 2004 09:39:04 GMT
Server: Apache/2.0.43 (Unix) mod_jk2/2.0.0
Set-Cookie: txlUserID=0; Path=/
Content-Type: text/html; charset=GBK
Content-Length: 0
Site www.xx.net has this header:

---Start of headers---

Date: Thu, 01 Jul 2004 09:39:04 GMT

Server: Apache/2.0.43 (Unix) mod_jk2/2.0.0

Set-Cookie: txlUserID=3723313; Path=/

Content-Type: text/html; charset=GBK

Content-Length: 0

Connection: close

---End of headers---

Then I use the code below to keep state betwen tow connection
and get what i want:


String url1= "http://www.xx.net/login.jsp?user=123&pas=123";

String url2= "http://www.xx.net/person.jsp";


URL url = new URL(urlName);

HttpURLConnection connection = url.openConnection();

BufferedReader inn = new BufferedReader(new InputStreamReader(connection.getInputStream()));


String line;

while((line = inn.readLine()) != null)

{

System.out.println(line);

}


URL SrcURL = new URL(url2);

URLConnection SrcConn = SrcURL.openConnection();

SrcConn.setDoOutput(true);

SrcConn.setUseCaches(false);

SrcConn.setRequestProperty("Content-Type",

"application/x-www-form-urlencoded");

SrcConn.setRequestProperty("Cookie","txlUserID=3723313");

DataOutputStream printout = new DataOutputStream(

SrcConn.getOutputStream());


StringBuffer content = new StringBuffer();


content.append("classID="+classid[j]);


printout.writeBytes(content.toString());

printout.flush();

printout.close();


InputStream in = SrcConn.getInputStream();

BufferedReader br = new BufferedReader(

new InputStreamReader(in));

String line1;

while((line1 = br.readLine()) != null) {

System.out.println(line1);

}


but with another site ,I get problem,it's header:


---Start of headers---

Server: Microsoft-IIS/5.0

Date: Wed, 30 Jun 2004 17:06:47 GMT

Content-Length: 45604

Content-Type: text/html

Expires: Wed, 30 Jun 2004 17:05:47 GMT

Set-Cookie: SetHomeMyOIC=Y; expires=Wed, 07-Jul-2004 17:06:46 GMT; domain=myoic.

com; path=/

Set-Cookie: SetHomeOIC=Y; expires=Wed, 07-Jul-2004 17:06:46 GMT; domain=oideaclu

b.com; path=/

Set-Cookie: ASPSESSIONIDCSCRARDA=GPLJKKPANBEGOFILMONACBAP; path=/

Cache-control: private

---End of headers---


what can i do? I don't know the difference
between the two site,help me!


 

   <<Less
About | Sitemap | Contact