1

Closed

POST Request without Content-Type header gives NullReferenceException

description

a POST request without a Content-Type results in NullReferenceException exception.
 
client code:
 
Public Function WebPost(url As String, content As String) As String
    Using wc As New WebClient()
        wc.Proxy = Nothing
        Return (wc.UploadString(New Uri(url), "POST", content))
    End Using
End Function
 
if one adds a Content-Type: e.g.: wc.Headers("Content-Type") = "application/mine"
then it works.
 

Server Exception Stack Trace

System.NullReferenceException: Object reference not set to an instance of an object.
at HttpServer.BodyDecoders.BodyDecoderCollection.Decode(Stream stream, ContentTypeHeader contentType, Encoding encoding) in C:\Smart_Elite\webserver.codeplex.com\HttpServer\BodyDecoders\BodyDecoderCollection.cs:line 51
at HttpServer.Server.DecodeBody(IRequest request) in C:\Smart_Elite\webserver.codeplex.com\HttpServer\Server.cs:line 164
at HttpServer.Server.HandleRequest(RequestEventArgs e) in C:\Smart_Elite\webserver.codeplex.com\HttpServer\Server.cs:line 229
at HttpServer.Server.OnRequest(Object sender, RequestEventArgs e) in C:\Smart_Elite\webserver.codeplex.com\HttpServer\Server.cs:line 302
 
 
the attached patch just adds a check for contentType being null.

file attachments

Closed Jan 31, 2012 at 4:51 AM by jgauffin

comments

angelblaze wrote Oct 3, 2011 at 2:03 PM

Forget to mention this is against v2, latest SVN.

wrote Jan 31, 2012 at 4:51 AM

wrote Feb 21, 2013 at 11:29 PM

wrote May 16, 2013 at 11:01 AM