Upload xml file- HttpWebRequest

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

    Upload xml file- HttpWebRequest

    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 "requestbod y" string?

    The code sends an xml file and a command.


    fso = new ActiveXObject(" Scripting.FileS ystemObject");
    xmlFile = fso.OpenTextFil e(AJobFile, 1);
    xmlText = xmlFile.ReadAll ();

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

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

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

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

    xmlhttp.open("P OST",url,false) ;
    xmlhttp.setRequ estHeader('Cont ent-type', 'multipart/form-data; boundary="'
    + boundStr + '"');
    xmlhttp.send(re questbody );


  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: Upload xml file- HttpWebRequest

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



    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 "requestbod y" string?
    >
    The code sends an xml file and a command.
    >
    >
    fso = new ActiveXObject(" Scripting.FileS ystemObject");
    xmlFile = fso.OpenTextFil e(AJobFile, 1);
    xmlText = xmlFile.ReadAll ();
    >
    var boundStr = 'h8w95k20d9';
    var boundary = '--' + boundStr;
    >
    var requestbody = [boundary,
    'Content-Disposition: file; name="F1";
    filename="'+AJo bFile+'"',
    'Content-Type: text/xml',
    '',
    xmlText,
    >
    boundary,
    'Content-Disposition: form-data; name="ImportJob s"',
    '',
    '0',
    boundary
    ].join('\r\n');
    >
    xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    url='http://'+WODAddress+'/JTI';
    >
    xmlhttp.open("P OST",url,false) ;
    xmlhttp.setRequ estHeader('Cont ent-type', 'multipart/form-data; boundary="'
    + boundStr + '"');
    xmlhttp.send(re questbody );
    >
    >
    >

    Comment

    Working...