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
Post a Comment