xml - You must write ContentLength bytes to the request stream before calling [Begin]GetResponse -
error: must write contentlength bytes request stream before calling [begin]getresponse.
can advise why getting above error when running following code
dim xml new system.xml.xmldocument() dim root xmlelement root = xml.createelement("root") xml.appendchild(root) dim username xmlelement username = xml.createelement("username") username.innertext = "xxxxx" root.appendchild(username) dim password xmlelement password = xml.createelement("password") password.innertext = "xxxx" root.appendchild(password) dim shipmenttype xmlelement shipmenttype = xml.createelement("shipmenttype") shipmenttype.innertext = "delivery" root.appendchild(shipmenttype) dim url = "xxxxxx" dim req webrequest = webrequest.create(url) req.method = "post" req.contenttype = "application/xml" req.headers.add("custom: api_method") req.contentlength = xml.innerxml.length dim newstream stream = req.getrequeststream() xml.save(newstream) dim response webresponse = req.getresponse() console.write(response.tostring())
probably length mismatch between character length of xml.innerxml
, written stream in xml.save(newstream)
. check if innerxml
includes xml version node, example. also, don't see specifying character encoding, affects size on wire. perhaps need save temporary memory stream, length of that, , send in request.
Comments
Post a Comment