Is it possible to use Msxml2.XMLHTTP to upload a text file?

Discussion in 'Javascript' started by Eric, Dec 23, 2003.

  1. Eric

    Eric Guest

    I have a form with an INPUT type=file in it.
    I have another button that calls a function to exercise the oHTTP below.

    I think I need to open with the path of the CGI script on the server.
    What should the send have in it?

    oHTTP.open("POST", ??????????, false);
    oHTTP.send(????????????????????);

    Thanks.
    Eric, Dec 23, 2003
    #1
    1. Advertising

  2. Eric wrote:

    > I have a form with an INPUT type=file in it.


    Then to upload the file let the user use an
    <input type="submit">
    button.
    > I have another button that calls a function to exercise the oHTTP below.
    >
    > I think I need to open with the path of the CGI script on the server.
    > What should the send have in it?
    >
    > oHTTP.open("POST", ??????????, false);
    > oHTTP.send(????????????????????);


    Msxml2.XMLHTTP can upload the contents of a text file, for instance you
    can send a HTTP POST request where the request body is the file content:

    var fso = new ActiveXObject('Scripting.FileSystemObject');
    var stream = fso_OpenTextFile('test20031223.txt', 1, false);
    var fileContent = stream.ReadAll();
    var httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
    httpRequest.open('POST', 'http://host/dir/file.asp', false);
    httpRequest.setRequestHeader('Content-Type', 'text/plain');
    httpRequest.setRequestHeader('Content-Length', fileContent.length);
    httpRequest.send(fileContent);

    The only problem is that usual from script within a HTML page loaded via
    HTTP from a web server security restrictions will not allow you to read
    files from the file system of the client.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 24, 2003
    #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. Paul
    Replies:
    0
    Views:
    492
  2. Raúl Martín
    Replies:
    1
    Views:
    10,774
    Natty Gur
    May 13, 2004
  3. BjörnHolmberg

    DotNet WS from VB6 with MSXML2.XMLHTTP

    BjörnHolmberg, Jul 5, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    359
    Ken Cox [Microsoft MVP]
    Jul 8, 2004
  4. Dmitry

    MSXML2.XMLHTTP

    Dmitry, Feb 25, 2004, in forum: ASP General
    Replies:
    1
    Views:
    274
    Mark Schupp
    Feb 25, 2004
  5. Roland Hall

    MSXML2.XMLHTTP

    Roland Hall, Dec 13, 2004, in forum: ASP General
    Replies:
    23
    Views:
    382
    Adrienne
    Dec 16, 2004
Loading...

Share This Page