Feeds:
Posts
Comments

Archive for February, 2011

Anyone of you experiencing STRANGE issues trying to connect to a Java web service –or- to embedded web servers (for instance sms gateways etc) ?

Well it could sound strange, but it happened 2 times in the same week here at my company and on totally different projects.

Basically it appears that if you send a POST using the HttpWebRequest sometimes the packets get fragmented on the IP protocol. This was NOT happening using the “old” XMLHttpRequest object of MSXML!

The actual point is that some web servers DO NOT LIKE the fragmentation. This TCP packet fragmentation introduce a wrong behavior of the web server that receives ONLY PART of the POST you performed. This leads to misunderstanding the actual request… and finally responding to you with errors or wrong behaviors.

It’s very hard to find this problem. The best tools that help understanding what is going on under the hoods are Network Protocol Analyzers such as Wireshark or Ethereal.

Some interesting lectures about that are:

Nagle’s Algorithm is Not Friendly towards Small Requests

If you want to solve the issue, use the following code:

 

Dim url As String = String.Format("http://{0}/smssend.cgi", txtAddress.Text)
Dim wr As HttpWebRequest = WebRequest.Create(url)
Dim msg As String = ".... .... ...."
Dim buffer As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(msg)

wr.ProtocolVersion = New System.Version(1, 0)
wr.Method = "POST"

System.Net.ServicePointManager.Expect100Continue = False
System.Net.ServicePointManager.UseNagleAlgorithm = False

 

Hope it helps!!

Adriano

Advertisements

Read Full Post »