This error occurs because the server is delivering a poorly formed HTTP header.
In the HTTP documentation 1.1 section 6.1 is written:
6.1 Status line
The first line of a reply message is the status line, which consists of the version of the protocol followed by a
numeric status code and its associated textual phrase, with each
element separated by SP characters. No CR or LF is allowed,
except in the final sequence of the CRLF.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html
Some servers deliver headers whose lines end or with CR
or LF
which ends up generating this validation error.
To get around this problem you will have to configure your requests to ignore the validation of HTTP headers.
To do this you must edit your file .config
. Remembering that it is web.config
if the application is a server and app.config
if the application is desktop.
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
The estate HttpWebRequestElement.UseUnsafeHeaderParsing
determines whether or not to ignore validation errors that occur during HTTP parsing.
While it is defined as false
the following validations will be executed during http analysis:
In end-of-line code, use CRLF; it is not allowed to use CR or LF alone.
Header names should not have spaces.
If there are multiple status lines, all additional status lines will be treated as malformed name/value pairs.
The status line must have a status description in addition to a status code.
This setting does not affect error issuance if header names containing non-ASCII characters in them.
Forgive the ignorance but should I attach your code at this point ? <? xml version="1.0" encoding="utf-8" ? > <Configuration> <startup> <supportedRuntime version="v4.0" sku=". Netframework,Version=v4.6.1" /> </startup> <system.net> <Settings> <httpWebRequest useUnsafeHeaderParsing="true" /> </Settings> </system.net> </Configuration>
– Cipher
That’s right. reference: Scheme of Web Settings, Configuration file schema for the . NET Framework
– Augusto Vasques
Sorry for the delay in commenting, but I did this procedure and the error continues. Any suggestions as to why the error continues ?
– Cipher
In the documentation of Webclient it is recommended to use the class Httpclient, make the attempt. If it doesn’t work, put a copy of the http headers in the question (pick with Chrome in the network tab inside the developer’s tools).
– Augusto Vasques