HttpWebRequest and headers with only newline

  • Thread starter Thread starter Mikael Svenson
  • Start date Start date
M

Mikael Svenson

Is there any way I can get the HttpWebRequest object to accept headers
with only \n in them?

When I go towards a particular url I get a ProtocolViolation error when
the headers in the received data only has \n to separate the fields.

If I make me a proxy and intercept the packets and change the \n to \r\n
it works just fine.

It seems to me that it's a bit strict to assume \r\n on http headers.

The same code works fine under Mono, so guess the Unix guys are a bit
more "forgiving" on these issues since \n is more unix like.

It's a bit hackish in my opinion to implement a proxy in order to get
this to work.

If anyone want the example url feel free to contact me.

-m
 
To those who are curious to the solution this is what I got from
Microsoft:

Add this to your config file:

<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>

-m
 
Mikael said:
Is there any way I can get the HttpWebRequest object to accept headers
with only \n in them?

When I go towards a particular url I get a ProtocolViolation error
when the headers in the received data only has \n to separate the
fields.

If I make me a proxy and intercept the packets and change the \n to
\r\n it works just fine.

It seems to me that it's a bit strict to assume \r\n on http headers.

That's because \r\n is the proper way to end a header line. HTTP's BNF
does not allow control characters to be header values.

Cheers,
 
Back
Top