HttpWebRequest - is it really this useless?

  • Thread starter Thread starter furty
  • Start date Start date
F

furty

I'm posting this again as it's been 2 weeks now and still not a single
reply,
surely someone must have come across this problem!

I'm trying to perform a HttpWebRequest that posts form data to the target
server - the problem is that the request *always* contains an Expect:
100-continue header, which on HTTP 1.0 servers results in a 500 error.

None of these seemingly obvious fixes work:

Set the HttpWebRequest.Expect property to null or String.Empty
Set the HttpWebRequest.ProtocolVersion to HttpVersion.Version10

Note that my class works perfectly with HTTP 1.1 servers, so I doubt there's
anything I've done incorrectly in code. Also note that the problem only
surfaces when you POST data to the server with the request, no post data =
no problem.

Searching google for this problem has given me a few people that have hit
the same problem, but not one valid workaround.

Help!
 
furty said:
I'm posting this again as it's been 2 weeks now and still not a single
reply,
surely someone must have come across this problem!

Maybe very few people need to POST to HTTP 1.0 servers which don't handle
100-Expect properly.
 
John Saunders said:
Maybe very few people need to POST to HTTP 1.0 servers which don't handle
100-Expect properly.
--
ditto.

I would just add that if you want a client that uses behaves differently for
this server, then write one.

Here's some sample code to get you started. HTTP, especially HTTP 1.0 is
pretty simple.

Any questions about the protocol, see the rfc
http://www.w3.org/Protocols/rfc1945/rfc1945

David



Class HTTP_RAW

Public Enum method
HTTP_POST
HTTP_GET
End Enum
Public Class Header
Private name_, value_ As String
Public Sub New(ByVal Name As String, ByVal value As String)
name_ = Name
value_ = value
End Sub
Public Sub New(ByVal HeaderLine As String)
Dim ipos As Integer = HeaderLine.IndexOf(":"c)
Name = HeaderLine.Substring(0, ipos).Trim
Value = HeaderLine.Substring(ipos + 1).Trim
End Sub
Public Property Name() As String
Get
Return name_
End Get
Set(ByVal Value As String)
name_ = Value
End Set
End Property
Public Property Value() As String
Get
Return value_
End Get
Set(ByVal Value As String)
value_ = Value
End Set
End Property
Public Overrides Function ToString() As String
Return name_ & "=" & value_
End Function
End Class
Public Shared Function Send(ByVal url As String, ByVal method As method,
ByVal body As String) As String
Dim host As String
Dim uri As New Uri(url)
Dim con As New Net.Sockets.TcpClient(uri.Host, uri.Port)
Dim s As IO.Stream = con.GetStream
Dim tw As New IO.StreamWriter(s)
tw.AutoFlush = True
If method = method.HTTP_GET Then
tw.WriteLine("GET {0} HTTP/1.0", uri.PathAndQuery)
tw.WriteLine("")
Else
tw.WriteLine("POST {0} HTTP/1.0", uri.PathAndQuery)
tw.WriteLine(New Header("Content-Length",
body.Length.ToString).ToString)
tw.WriteLine("")
tw.Write(body)
End If

Dim tr As New IO.StreamReader(s)
Dim line As String


Dim headers As New SortedList()
line = tr.ReadLine
Dim status As Integer = Integer.Parse(line.Substring("HTTP/1.0 ".Length,
3))
If status <> 200 Then
con.Close()
Throw New Exception("HTTP staus " & status.ToString)
End If
line = tr.ReadLine
Do Until line = ""
Dim h As New Header(line)
headers.Add(h.Name, h)
line = tr.ReadLine
Loop
If headers.Contains("Content-Length") Then
Dim contentLength As Integer
Dim resp(contentLength - 1) As Char
Dim br As Integer = 0
Do While br < contentLength
br += tr.Read(resp, br, contentLength - br)
Loop
con.Close()
Return New String(resp)
Else
Dim resp As String = tr.ReadToEnd
con.Close()
Return resp
End If



End Function
End Class
 
There is a fix posted by MS on this issue. Go to support.microsoft.com and
search for it. I dont remember the Qnum offhand, but if you search in google
you should be able to find my previous responses on this issue.

feroze
================
This response is provided as-is. It offers no warranties and confers no
rights.
 
Hi

I don't have the same problem as you although i thinik
you might a solution to my problem.

i need to send files from a vb.net program(actually an addin) to a server
using http. Any ideas or code that i can use?

Please i am really struggling with this thing.

danie
 
Back
Top