Can't send cookies using XMLHTTP

Discussion in 'Javascript' started by Lu Wei, Aug 7, 2006.

  1. Lu Wei

    Lu Wei Guest

    Hello,

    I'm writing a script to send posts to a web forum. I find that
    MSXML2.XMLHTTP object could communicate with web server but I can't make
    it send cookie which is needed for post authentication. I have searched
    google and read some articles including:

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;q290899
    http://support.microsoft.com/kb/234486/en-us

    But setting the cookie twice as suggested didn't work. Here is my script:

    //log in
    var site="bbs.nju.edu.cn";
    var body="login string"
    var xmlhttp = WScript.CreateObject("MSXML2.XMLHTTP")
    xmlhttp.open("POST","http://"+site+"/bbslogin?type=2", false);
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlhttp.send(body);
    WScript.Echo(xmlhttp.responseText); // log in will succeed

    //post request
    var _U_NUM, _U_UID, _U_KEY; //cookie names
    ....// assign values returned by login process to cookie names
    xmlhttp.open("GET","http://"+site+"/bbspst?board=test", false);
    xmlhttp.setRequestHeader("Cookie", "_U_NUM="+_U_NUM+";
    _U_UID="+_U_UID+"; _U_KEY="+_U_KEY+"; FOOTKEY=;");
    xmlhttp.setRequestHeader("Cookie", "_U_NUM="+_U_NUM+";
    _U_UID="+_U_UID+"; _U_KEY="+_U_KEY+"; FOOTKEY=;");
    xmlhttp.send();
    WScript.Echo(xmlhttp.responseText); // this request will fail

    I used ethereal and confirmed that no "Cookie:" header is sent. Could it
    really be done by javascript to post articles to a web forum? What else
    could I do? Any help is appreciated.

    Some system info: win98se, WSH5.6, msxml.dll version is 8.0.6730.0

    --
    Regards
    Lu Wei
     
    Lu Wei, Aug 7, 2006
    #1
    1. Advertising

  2. Lu Wei

    Lu Wei Guest

    More readings have convinced me that this is a "known" problem exists
    with xmlhttp in msxml 3 and 4.

    So, could anybody tell me how to post to web (with customized http
    cookie header) through javascript (not in a browser but in WSH)? And
    better it could be executed in win98se.
    --
    Regards
    Lu Wei
     
    Lu Wei, Aug 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. _Who
    Replies:
    7
    Views:
    2,768
  2. kenny

    XMLHTTP SEND and 0x800C0005 error

    kenny, Jan 29, 2004, in forum: ASP General
    Replies:
    2
    Views:
    392
    Aaron Bertrand - MVP
    Jan 29, 2004
  3. RK
    Replies:
    5
    Views:
    1,082
    Jim Ley
    Aug 8, 2004
  4. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    433
    Matt Kruse
    Nov 9, 2006
  5. jr
    Replies:
    6
    Views:
    173
    Denis McMahon
    Aug 1, 2010
Loading...

Share This Page