Failure to do persistent connection

Aliza (aliza_blue@yahoo.com)
Mon, 8 Nov 1999 08:18:55 -0000


This is a multi-part message in MIME format.

------=_NextPart_000_0039_01BF29C1.E6807B30
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

I'm implementing a program to connect a site and walk through
the first few pages. To do this I choose my.yahoo.com as my
target, and start to implement as follows:

I use a URL instance to connect to "http: file://my.yahoo.com" url.
It responses with a single cookie header as:

  Set-Cookie: B=3Dsomevalue; expires=3Ddate; path=3D/ ; =
domain=3D.yahoo.com;

My program parses this cookie and prepare the following string
to return back in the next POST request:

  Cookie: $version=3D0; B=3Dsomevalue; $path=3D/; $domain=3D.yahoo.com
  (The 'B=3Dsamoevalue' format is tested too)
 =20
The program will attach a parameter list for logging in to
MyYahoo in the following format:

  param1=3Dvalue1&param2=3Dvalue2&...

(The parameters list is complete and all parameters name are
spelled correctly), but the server will response with a new
cookie and send a page that contains a message which says "An
Error Occurred Setting Your User Cookie".

I tried every thing I guessed, but no success. I don't know
what is the problem. The last tested code is attached bellow.

Thank you in advance for your kind attentions.
@liz@

---------------------------------------

 System.getProperties().put( "proxySet",  "true" );
 System.getProperties().put( "proxyHost", "128.1.1.1" );
 System.getProperties().put( "proxyPort", "80" );
=20
 URL url =3D new URL("http://my.yahoo.com");
 HttpURLConnection connection =3D =
(HttpURLConnection)url.openConnection();
  =20
 connection.setRequestMethod("GET");
 connection.setRequestProperty("Connection", "Keep-Alive");
 connection.setRequestProperty("Proxy-Connection", "Keep-Alive");
 connection.setRequestProperty("Cashe-Control", "no-cashe");
 connection.setDoOutput(true);
 connection.setUseCaches(false);
 Object content =3D connection.getContent();
  =20
 Cookie cookie =3D null;
 int    index  =3D 0;
 String header =3D connection.getHeaderField(index);
 String key    =3D connection.getHeaderFieldKey(index);
 =20
 StringBuffer cookieStr =3D new StringBuffer("");
  =20
 while (header !=3D null) {
  if ("Set-Cookie".equalsIgnoreCase(key)) {
   // parses the cookie header
   cookie =3D parseCookie(header);
   if (cookieStr.length() > 0) {
    cookieStr.append(",");
   }
   // converts the cookie to this format:
   //    $version=3D1; name=3Dvalue; $path=3Dpath; $domain=3Ddomain
   cookieStr.append(toRFC_2109(cookie));
  }
   =20
  index++;
  header =3D connection.getHeaderField(index);
  key    =3D connection.getHeaderFieldKey(index);
   =20
 }

 BufferedInputStream in =3D (BufferedInputStream)content;
 OutputStream out =3D new FileOutputStream(args[0]);
 int c;
 while ((c=3Din.read())>=3D 0){
  out.write((char)c);
 }
 out.close();
  =20
 =20
 url =3D new URL("http://login.yahoo.com/config/login");
 connection =3D (HttpURLConnection)url.openConnection();
  =20
 SimpleDateFormat formatter =3D new SimpleDateFormat ("EEE, dd MMM yyyy =
HH:mm:ss 'GMT'");
 Date now =3D new Date();
 String dateStr =3D formatter.format(now);
 System.out.println("Date=3D<" + dateStr + ">");
  =20
 connection.setRequestMethod("POST");
 connection.setRequestProperty("Cashe-Control", "no-cashe");
 connection.setRequestProperty("Connection", "Keep-Alive");
 connection.setRequestProperty("Proxy-Connection", "Keep-Alive");
 connection.setRequestProperty("Date", dateStr);
 connection.setDoOutput(true);
 connection.setUseCaches(false);
  =20
  =20
 if ( ! "".equals(cookieStr)) {
  connection.setRequestProperty("Cookie", cookieStr.toString());
 }

 String params =3D URLEncoder.encode(".tries")      + "=3D" + =
URLEncoder.encode("1")  + "&" +=20
   URLEncoder.encode(".done")       + "=3D" + =
URLEncoder.encode("http://my.yahoo.com") + "&" +
   URLEncoder.encode(".src")        + "=3D" + URLEncoder.encode("my") + =
"&" +
   //... other parames
  =20

 connection.setRequestProperty("Content-Length", =
Integer.toString(params.length()));
 DataOutputStream o =3D new =
DataOutputStream(connection.getOutputStream());

 o.writeBytes(params);
 o.flush();
 o.close();
  =20
 content =3D connection.getContent();
  =20
 in =3D (BufferedInputStream)content;
 out =3D new FileOutputStream(args[1]);
 while ((c=3Din.read())>=3D 0){
  out.write((char)c);
 }
 out.close();
  =20
 System.out.println();
=20


------=_NextPart_000_0039_01BF29C1.E6807B30
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Hi,
 
I'm implementing a program to connect a = site and=20 walk through
the first few pages. To do this I choose my.yahoo.com as = my
target, and start to implement as follows:
 
I use a URL instance to connect to = "http: file://my.yahoo.com" url.
It = responses with a=20 single cookie header as:
 
  Set-Cookie: B=3Dsomevalue; = expires=3Ddate;=20 path=3D/ ; domain=3D.yahoo.com;
 
My program parses this cookie and = prepare the=20 following string
to return back in the next POST = request:
 
  Cookie: $version=3D0; = B=3Dsomevalue; $path=3D/;=20 $domain=3D.yahoo.com
  (The 'B=3Dsamoevalue' format is tested = too)
 =20
The program will attach a parameter list for logging in = to
MyYahoo in the=20 following format:
 
 =20 param1=3Dvalue1&param2=3Dvalue2&...
 
(The parameters list is complete and = all parameters=20 name are
spelled correctly), but the server will response with a=20 new
cookie and send a page that contains a message which says = "An
Error=20 Occurred Setting Your User Cookie".
 
I tried every thing I guessed, but no = success. I=20 don't know
what is the problem. The last tested code is attached=20 bellow.
Thank you in advance for your kind=20 attentions.
@liz@
 
---------------------------------------

 System.getProperties().put(=20 "proxySet",  "true" );
 System.getProperties().put( = "proxyHost",=20 "128.1.1.1" );
 System.getProperties().put( "proxyPort", "80"=20 );
 
 URL url =3D new=20 URL("http://my.yahoo.com");
 HttpURLConnection connection =3D=20 (HttpURLConnection)url.openConnection();
   
 c= onnection.setRequestMethod("GET");
 connection.setRequestProperty= ("Connection",=20 "Keep-Alive");
 connection.setRequestProperty("Proxy-Connection",= =20 "Keep-Alive");
 connection.setRequestProperty("Cashe-Control",=20 "no-cashe");
 connection.setDoOutput(true);
 connection.s= etUseCaches(false);
 Object=20 content =3D = connection.getContent();
   
 Cookie cookie=20 =3D null;
 int    index  =3D = 0;
 String header =3D=20 connection.getHeaderField(index);
 String key    = =3D=20 connection.getHeaderFieldKey(index);
  
 StringBuffe= r=20 cookieStr =3D new StringBuffer("");
   
 while = (header=20 !=3D null) {
  if ("Set-Cookie".equalsIgnoreCase(key))=20 {
   // parses the cookie = header
   cookie =3D=20 parseCookie(header);
   if (cookieStr.length() > 0) = {
    cookieStr.append(",");
   = }
   //=20 converts the cookie to this = format:
   //   =20 $version=3D1; name=3Dvalue; $path=3Dpath;=20 $domain=3Ddomain
   cookieStr.append(toRFC_2109(cookie)= );
  }
    
  index++;  header=20 =3D = connection.getHeaderField(index);
  key    = =3D=20 connection.getHeaderFieldKey(index);
    
 = ;}
 
 BufferedInputStream in =3D=20 (BufferedInputStream)content;
 OutputStream out =3D new=20 FileOutputStream(args[0]);
 int c;
 while = ((c=3Din.read())>=3D=20 0){
  out.write((char)c);
 }
 out.close();   
  
 url=20 =3D new URL("http://login.yahoo.com/config/login");
 connection = =3D=20 (HttpURLConnection)url.openConnection();
   
 S= impleDateFormat=20 formatter =3D new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss=20 'GMT'");
 Date now =3D new Date();
 String dateStr =3D=20 formatter.format(now);
 System.out.println("Date=3D<" + = dateStr +=20 ">");
   
 connection.setRequestMethod("POST= ");
 connection.setRequestProperty("Cashe-Control",=20 "no-cashe");
 connection.setRequestProperty("Connection",=20 "Keep-Alive");
 connection.setRequestProperty("Proxy-Connection",= =20 "Keep-Alive");
 connection.setRequestProperty("Date",=20 dateStr);
 connection.setDoOutput(true);
 connection.setU= seCaches(false);
   
   
 if = ( ! "".equals(cookieStr))=20 {
  connection.setRequestProperty("Cookie",=20 cookieStr.toString());
 }
 
 String params =3D=20 URLEncoder.encode(".tries")      + "=3D" +=20 URLEncoder.encode("1")  + "&" +=20
   URLEncoder.encode(".done")    &= nbsp; =20 + "=3D" + URLEncoder.encode("http://my.yahoo.com") + "&"=20 +
   URLEncoder.encode(".src")    &= nbsp;  =20 + "=3D" + URLEncoder.encode("my") + "&" +
   //... = other=20 parames
   
 
 connection.setRequestProperty("Content-Length",=20 Integer.toString(params.length()));
 DataOutputStream o =3D new=20 DataOutputStream(connection.getOutputStream());
 
 o.writeBytes(params);
 o.flush();
 o.close= ();
   
 content=20 =3D connection.getContent();
   
 in =3D=20 (BufferedInputStream)content;
 out =3D new=20 FileOutputStream(args[1]);
 while ((c=3Din.read())>=3D=20 0){
  out.write((char)c);
 }
 out.close();   
 System.out.println();
 
<= /DIV> ------=_NextPart_000_0039_01BF29C1.E6807B30--