Vb.Net - Bytes Written Exceed the Content-Length bytes in XML Post -
ugh, keep getting protocolviolationexception "bytes written stream exceed content-length bytes size specified." on following code.
i've tried setting content-length numerous ways no success.
dim url = "https://domain.com" dim req webrequest = webrequest.create(url) req.method = "post" req.contenttype = "application/xml" dim utf8 new utf8encoding() req.contentlength = utf8.getbytecount(xml.outerxml) xml.save(req.getrequeststream()) // throws exception req.getrequeststream().close() dim httpresp webresponse = req.getresponse() dim streader streamreader = new streamreader(httpresp.getresponsestream()) dim strresponse string strresponse = streader.readtoend() console.writeline(strresponse)
i've tried setting content-length using xml.outxml.length
try webclient, makes code easier , takes care of flushing , disposing streams:
dim xml new xmldocument xml.loadxml("<foo>abc</foo>") using client webclient = new webclient client.headers.item(httprequestheader.contenttype) = "application/xml" dim data byte() = encoding.utf8.getbytes(xml.outerxml) console.writeline(encoding.utf8.getstring(client.uploaddata("https://domain.com", data))) end using
Comments
Post a Comment