HttpWebRequest in c# do not work with .net 4.5 -
i'm working on c# project send xml server , receives xml response.
.net framework 4.0 installed works fine.
.net framework 4.5 installed throws exception:
system.nullreferenceexception: der objektverweis wurde nicht auf eine objektinstanz festgelegt. bei system.domainnamehelper.idnequivalent(string hostname) bei system.uri.get_idnhost() bei system.net.httpwebrequest.getsafehostandport(uri sourceuri, boolean adddefaultport, boolean forcepunycode) bei system.net.httpwebrequest.generateproxyrequestline(int32 headerssize) bei system.net.httpwebrequest.serializeheaders() bei system.net.httpwebrequest.endsubmitrequest() bei system.net.httpwebrequest.checkdeferredcalldone(connectstream stream) bei system.net.httpwebrequest.begingetresponse(asynccallback callback, object state) bei fahrzeugverwaltungsserver.outsideworld.man_integrationsserver.rawcommunication.isserver.dopostandget()`
i use method begingetresponse
, parameters there not null.
know what's wrong?
why work 4.0 not 4.5?
did forget set up?
edit 1
private void dopostandget() { try { //caching inform(systemicons.information, translations.isserver_postandget_0); trace.traceinformation("out:\n" + beautify(inputxml)); string c = cache.get(inputxml.outerxml); if (c != null) { xmldocument docl = new xmldocument(); docl.loadxml(c); inform(systemicons.information, translations.isserver_postandget_1); printindocument(docl, "aus cache."); this.doc = docl; } //read access information: uribuilder urib = new uribuilder("http", manhaendlerdaten.is_host, 9005, manhaendlerdaten.is_path); urib.username = manhaendlerdaten.is_user; urib.password = manhaendlerdaten.is_password; string proxyuser = manhaendlerdaten.is_proxy_user; string proxypassword = manhaendlerdaten.is_proxy_password; // create credentials request's header: var proxy = convert.tobase64string( encoding.utf8.getbytes(proxyuser + ":" + proxypassword)); var user = convert.tobase64string( encoding.utf8.getbytes(urib.username + ":" + urib.password)); //set proxy when needed: try { webrequest.defaultwebproxy = new webproxy(manhaendlerdaten.is_proxy_ip, manhaendlerdaten.is_proxy_port); if (webrequest.defaultwebproxy == null) trace.writeline(string.format("webrequest.defaultwebproxy ist null. {0}, {1}", manhaendlerdaten.is_proxy_ip, manhaendlerdaten.is_proxy_port)); } catch (exception e) { trace.traceerror("1\n" + e.tostring()); debug.writeline(translations.isserver_postandget_3); webrequest.defaultwebproxy = null; //speed further request avoiding proxy-auto-detect //pass when no proxy specified } // system.net.servicepointmanager.expect100continue = false //this nasty 1 if not set false client = (httpwebrequest)webrequest.create(urib.uri); //encodings: client.headers.add("accept-encoding", "deflate"); client.contenttype = "text/xml; charset=utf-8"; client.accept = "text/xml; charset=utf-8"; client.headers.add("soapaction", "\"\""); //authentification: client.headers.add("proxy-authorization", "basic " + proxy); client.headers.add("authorization", "basic " + user); //connection , protocol: client.host = urib.host; client.useragent = translations.fullservicename; client.protocolversion = httpversion.version10; client.keepalive = true; client.method = webrequestmethods.http.post; client.timeout = 60000; client.proxy = new webproxy(manhaendlerdaten.is_proxy_ip, manhaendlerdaten.is_proxy_port); if (client.proxy == null) trace.writeline(string.format("client.proxy ist null. {0}, {1}", manhaendlerdaten.is_proxy_ip, manhaendlerdaten.is_proxy_port)); client.readwritetimeout = 60000; //accept cookies within isserver-instance if (this.cookiecont == null) { this.cookiecont = new cookiecontainer(); } client.cookiecontainer = cookiecont; inform(systemicons.information, translations.isserver_postandget_7); //post request: using (stream to_request = client.getrequeststream()) { inputxml.save(to_request); to_request.flush(); } requeststate myrequeststate = new requeststate(); myrequeststate.request = client; webrequestresponse = false; iasyncresult asyncresult = client.begingetresponse(new asynccallback(finishwebrequest), myrequeststate); while (webrequestresponse == false) { thread.sleep(100); } } catch (exception e) { trace.traceerror(e.tostring()); throw e; } }
edit 2
in config file use appsettings individual settings. like:
<add key="database_connection" value="firebird"/>
to honest targeting .net 4.5 have using httpclient
instead of httpwebrequest.
Comments
Post a Comment