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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

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

    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("POS T", ??????????, false);
    oHTTP.send(???? ??????????????? ?);

    Thanks.
  • Martin Honnen

    #2
    Re: Is it possible to use Msxml2.XMLHTTP to upload a text file?



    Eric wrote:
    [color=blue]
    > I have a form with an INPUT type=file in it.[/color]

    Then to upload the file let the user use an
    <input type="submit">
    button.[color=blue]
    > 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("POS T", ??????????, false);
    > oHTTP.send(???? ??????????????? ?);[/color]

    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.FileS ystemObject');
    var stream = fso.OpenTextFil e('test20031223 .txt', 1, false);
    var fileContent = stream.ReadAll( );
    var httpRequest = new ActiveXObject(' Msxml2.XMLHTTP' );
    httpRequest.ope n('POST', 'http://host/dir/file.asp', false);
    httpRequest.set RequestHeader(' Content-Type', 'text/plain');
    httpRequest.set RequestHeader(' Content-Length', fileContent.len gth);
    httpRequest.sen d(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


    Comment

    Working...