Atlas 2: HTTP POST is slower and it’s default in Atlas

Atlas by default makes HTTP POST for all AJAX calls. Http POST
is more expensive than Http GET. It transmits more bytes over the
wire, thus taking precious network time and it also makes ASP.NET
do extra processing on the server end. So, you should use Http Get
as much as possible. However, Http Get does not allow you to pass
objects as parameters. You can pass numeric, string and date only.
When you make a Http Get call, Atlas builds an encoded url and
makes a hit to that url. So, you must not pass too much content
which makes the url become larger than 2048 chars. As far as I
know, that’s what is the max length of any url.

Another evil thing about http post is, it’s actually 2 calls.
First browser sends the http post headers and server replies with
“HTTP 100 Continue”. When browser receives this, it sends the
actual body. Here’s what the headers look like:

Request:

POST / Atlas1 / Default . aspx
HTTP
/ 1.1 __serviceMethodName = Timeout&__serviceMethodParams
= {}&__VIEWSTATE =/ wEPDwUJMTY3NTY1MjM2ZGSlWDXIdYj44hhTUd0z8yyp1q
%2 bUtw %3
d %3 d Response:
HTTP
/ 1.1 100
Continue Server: ASP
. NET Development Server / 8.0
. 0.0 Date :
Mon
, 11 Sep
2006 15 :
04 : 13
GMT Content-Length:
0

After getting this clearance from the server, the actual body is
sent. This is done in order to prevent long posts which are not
going to succeed anyway if the server cannot accept it. But it
comes at the cost of network latency.

So, Http Get should be at least twice faster than Http Post.

Here’s how you make Http GET calls in Atlas:

Step 1: Decorate web method with attribute

First you need to put a special attribute on the web method:

[WebMethod] [WebOperation(
true )] public string HelloWorld() { return Hello
World
; }

Step 2: Set useGetMethod=true while making the call

Here’s how you call the web method using Http Get:

WebService.HelloWorld( {
useGetMethod:
true
, onMethodComplete:
function (result) { debug.dump(result); } } );

Note: It needs to be a web service (.asmx). It will not work if
you use it on page methods.

Please see this page
in Atlas Quickstart
for further info.

20 thoughts on “Atlas 2: HTTP POST is slower and it’s default in Atlas”

Leave a Reply