Upload xml file- HttpWebRequest

Discussion in 'ASP .Net' started by Rob, May 12, 2008.

  1. Rob

    Rob Guest

    I'm trying to translate the following code in vb.net code to be used in a
    web service. Really I can't understand well it. I would like to use
    httpWebRequest but I don't know.... Do I have to use headers? How can I
    translate the "requestbody" string?

    The code sends an xml file and a command.


    fso = new ActiveXObject("Scripting.FileSystemObject");
    xmlFile = fso_OpenTextFile(AJobFile, 1);
    xmlText = xmlFile.ReadAll();

    var boundStr = 'h8w95k20d9';
    var boundary = '--' + boundStr;

    var requestbody = [boundary,
    'Content-Disposition: file; name="F1";
    filename="'+AJobFile+'"',
    'Content-Type: text/xml',
    '',
    xmlText,

    boundary,
    'Content-Disposition: form-data; name="ImportJobs"',
    '',
    '0',
    boundary
    ].join('\r\n');

    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    url='http://'+WODAddress+'/JTI';

    xmlhttp.open("POST",url,false);
    xmlhttp.setRequestHeader('Content-type', 'multipart/form-data; boundary="'
    + boundStr + '"');
    xmlhttp.send(requestbody );
    Rob, May 12, 2008
    #1
    1. Advertising

  2. Rob

    bruce barker Guest

    yes. its a standard browser fileupload. check the w3c specs to understand the
    format:

    http://www.w3.org/Protocols/

    or you can use webclient which has support for this (fileupload). just be
    sure to set the content-type.


    -- bruce (sqlwork.com)


    "Rob" wrote:

    > I'm trying to translate the following code in vb.net code to be used in a
    > web service. Really I can't understand well it. I would like to use
    > httpWebRequest but I don't know.... Do I have to use headers? How can I
    > translate the "requestbody" string?
    >
    > The code sends an xml file and a command.
    >
    >
    > fso = new ActiveXObject("Scripting.FileSystemObject");
    > xmlFile = fso_OpenTextFile(AJobFile, 1);
    > xmlText = xmlFile.ReadAll();
    >
    > var boundStr = 'h8w95k20d9';
    > var boundary = '--' + boundStr;
    >
    > var requestbody = [boundary,
    > 'Content-Disposition: file; name="F1";
    > filename="'+AJobFile+'"',
    > 'Content-Type: text/xml',
    > '',
    > xmlText,
    >
    > boundary,
    > 'Content-Disposition: form-data; name="ImportJobs"',
    > '',
    > '0',
    > boundary
    > ].join('\r\n');
    >
    > xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    > url='http://'+WODAddress+'/JTI';
    >
    > xmlhttp.open("POST",url,false);
    > xmlhttp.setRequestHeader('Content-type', 'multipart/form-data; boundary="'
    > + boundStr + '"');
    > xmlhttp.send(requestbody );
    >
    >
    >
    bruce barker, May 12, 2008
    #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. =?Utf-8?B?U2FyYXY=?=

    Upload a file without file Upload control - ASP.Net

    =?Utf-8?B?U2FyYXY=?=, Aug 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,422
    Bruce Barker
    Aug 3, 2005
  2. Roshawn Dawson

    Sending an xml file in HttpWebRequest

    Roshawn Dawson, Sep 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,882
    Roshawn Dawson
    Sep 21, 2005
  3. Roland Riess
    Replies:
    0
    Views:
    2,838
    Roland Riess
    Mar 7, 2006
  4. Heather Fraser
    Replies:
    0
    Views:
    614
    Heather Fraser
    Jul 5, 2004
  5. Gert Conradie

    HttpWebrequest Upload Of (image) Binary file.

    Gert Conradie, Jun 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    1,549
Loading...

Share This Page