c# - Server error 500 at the time of post method -
i facing problem make post method c# got 500 internal server error.
here code making call take time , include xml document.
i have made same call using arc plugin, work fine. here in .net facing problem
string url = "http://10.107.2.153/onvif/device_service"; //system.net.webrequest req = system.net.webrequest.create(url);// + (string.isnullorempty(data) ? "" : "?" + data)); httpwebrequest req = (httpwebrequest)webrequest.create(url); //req.credentials = new networkcredential("admin","cisco123"); req.method = "post"; req.contenttype = "text/xml;charset=utf-8";//action=\"http://www.onvif.org/ver10/device/wsdl/getsystemdateandtime\""; req.headers.add("soapaction","\"http://www.onvif.org/ver10/device/wsdl/getsystemdateandtime"); string postdata = "<s:envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:body xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\"><getsystemdateandtime xmlns=\"http://www.onvif.org/ver10/device/wsdl\"/></s:body></s:envelope>"; byte[] bytearray = system.text.encoding.ascii.getbytes(postdata);//encoding.utf8.getbytes(postdata); req.contentlength = bytearray.length; stream datastream = req.getrequeststream(); datastream.write(bytearray, 0, bytearray.length); datastream.close(); try { system.net.httpwebresponse resp = (httpwebresponse)req.getresponse(); } catch (webexception wex) { webresponse errresp = wex.response; using (stream respstream = errresp.getresponsestream()) { streamreader reader = new streamreader(respstream); string text = reader.readtoend(); } }
by adding protocolversion parameter issue resolved.
req.protocolversion = httpversion.version10
it may issue because of protocol mismatch.
Comments
Post a Comment