c# - Ignoring SSL certificate error leads to WebRequest status 406 -
i'm writing own test application api, has own test application, works fine.
it ignores certificate errors using system.net.servicepointmanager.servercertificatevalidationcallback = delegate { return true; };// allow ssl peer certificates (for testing only!)
when run test app, connects , registers fine. however, when try connect application, response code 406. thing is, both applications same.
the real difference is, don't provide gui providing data needed connecting, since hardcode them (just testing). i'm calling same method, use connect button , error code.
i have source of api right next me, i'm not allowed publish it. instead, send method causes error code:
public wwsvcc_response rawhttprequestbytes(string method, string path, webheadercollection headers, dynamic body) { if (body != null && (body byte[]) == null && (body dictionary<string, dynamic>) == null) throw (new exception("type of parameter \"body\" invalid")); if (body != null && method == "get") method = "put"; byte[] bodybytes = null; webresponse res = null; try { string uri = ((ssl) ? "https" : "http") + "://" + host + ":" + port.tostring() + rootpath + path; webrequest req = webrequest.create(uri); req.headers = headers; ((httpwebrequest)req).useragent = "wwsvc .net client"; ((httpwebrequest)req).accept = "*/*"; req.method = method; req.timeout = 10000; stream rs; if (body != null) { bodybytes = body byte[]; if (bodybytes == null) bodybytes = jsonobjectencoder(body); req.contentlength = bodybytes.length; req.contenttype = "application/json"; rs = req.getrequeststream(); rs.write(bodybytes, 0, bodybytes.length); rs.close(); } try { res = req.getresponse(); } catch (webexception ex) { res = ex.response; system.diagnostics.trace.writeline(ex.tostring()); } rs = res.getresponsestream(); byte[] resbytes; using (memorystream ms = new memorystream()) { int red = 1; byte[] buffer = new byte[4096]; while (red > 0) { red = rs.read(buffer, 0, buffer.length); if (red > 0) ms.write(buffer, 0, red); } resbytes = ms.toarray(); } rs.close(); wwsvcc_response r = new wwsvcc_response(this, (int)((httpwebresponse)res).statuscode, resbytes, null, null, headers, bodybytes); lastresponse = r; return r; } catch (exception ex) { system.diagnostics.debug.writeline(ex.tostring()); wwsvcc_response r = new wwsvcc_response(this, (res == null) ? 0 : (int)((httpwebresponse)res).statuscode, null, null, ex, headers, bodybytes); lastresponse = r; return r; } }
at point, tried everything, know work. disabling "ignore certificate" workaround causes request fail, due server application being test server invalid ssl certificate. server app works ssl, since works confidental data.
do have idea, problem is?
Comments
Post a Comment