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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -