c# - Content-Length or Chunked Encoding cannot be set for an operation that does not write data -


i error :

content-length or chunked encoding cannot set operation not write data

how can resolve it?

here code:

string xmlreq="<?xml version='1.0' encoding='iso-8859-1'?><methodcall><methodname>getbalanceanddate</methodname><params><param><value><struct><member><name>originnodetype</name><value><string>ext</string></value></member><member><name>originhostname</name><value><string>fashionmasala</string></value></member><member><name>transactiontype</name><value><string>fashionmasala</string></value></member><member><name>transactioncode</name><value><string>fashionmasala</string></value></member><member><name>externaldata1</name><value><string>fashionmasala_vas</string></value></member><member><name>externaldata2</name><value><string>fashionmasala_vas</string></value></member><member><name>origintransactionid</name><value><string>1</string></value></member><member><name>origintimestamp</name><value><datetime.iso8601>"+datetime.utcnow.tostring("o")+"</datetime.iso8601></value></member><member><name>subscribernumbernai</name><value><int>1</int></value></member><member><name>subscribernumber</name<value><string>923030025659</string></value></member></struct></value></param></params></methodcall>";  httpwebrequest webrequest =(httpwebrequest)webrequest.create(url); webrequest.contenttype = "text/xml"; webrequest.method = "get"; webrequest.contentlength =xmlreq.length; webrequest.headers.add("authorization", "basic " + oatuh); httpwebresponse webresponse =(httpwebresponse)webrequest.getresponse(); 

you're not writing (or encoding) data. try this:

string xmlreq = ... var data = encoding.ascii.getbytes( xmlreq );  var webrequest = (httpwebrequest)webrequest.create( url ); webrequest.contenttype = "text/xml"; webrequest.method = "get"; webrequest.contentlength = data.length; webrequest.headers.add( "authorization", "basic " + oatuh );  using( var stream = webrequest.getrequeststream() )     stream.write( data, 0, data.length );  var webresponse = (httpwebresponse)webrequest.getresponse(); 

i went ascii because why not, you'll have decide on proper encoding obviously.

edit: , also, codesinchaos points out, doesn't make sense send data in request. sure you're not supposed use post?


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -