C# read stream get WebException -


i'm trying open connection server , response body, image. want save image, , later display in picturebox. here code:

try     {         var response = webrequest.create(string.format(url + "?t=webwx&_={0}", timestamp));         var stream = response.getrequeststream();         image image = image.fromstream(stream);         qe_img.image = image;         qe_img.height = image.height;         qe_img.width = image.width;      } catch (exception e)      {         console.writeline(e);      } 

i get:

exception thrown: 'system.net.protocolviolationexception' in system.dll system.net.protocolviolationexception: cannot send content-body verb-type.    @ system.net.httpwebrequest.checkprotocol(boolean onrequeststream)    @ system.net.httpwebrequest.getrequeststream(transportcontext& context)    @ system.net.httpwebrequest.getrequeststream()    @ windowsformsapplication1.form1.showqrimage() in c:\users\morgan\documents\visual studio 2015\projects\windowsformsapplication1\windowsformsapplication1\form1.cs:line 70 

but webexception. i'm new c#, wonder wrong here. thanks.

try this

 try             {                 var request = webrequest.create(string.format(url + "?t=webwx&_={0}", timestamp));                  using (webresponse response = request.getresponse())                 {                     using (stream stream = response.getresponsestream())                     {                         image image = image.fromstream(stream);                         qe_img.image = image;                         qe_img.height = image.height;                         qe_img.width = image.width;                       }                 }              }             catch (exception e)             {                 console.writeline(e);             } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -