Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, July 12, 2011

c# .NET HttpWebRequest slow - Expect 100 continue!

Another tech stuff, at least as I am not posting lately. So, we were sending HTTP requestso the server and against a previous (3rd party) version it was extremely slow. Any browsing would suggest to change buffering, async mode or turning off proxy, but none helped.

When we changed POST to GET, this problem dismissed!
When we rewrote using sockets, the problem dismissed, but could not take the risk of an own implementation on a production system.

Profiling showed the bottleneck is this line:
HttpWebResponse r = (HttpWebResponse)request.GetResponse();

the poll method. Finally the solution was
Expect 100 Continue
Never heard of? :) What a surprise, turn itt off and give it a try. For further explanation search the web for it.

System.Net.ServicePointManager.Expect100Continue = false;
or
request.ServicePoint.Expect100Continue = false;

Good luck.

Wednesday, January 20, 2010

C# - Variable xxx is already defined in this scope

WTF!?

after coming back from holidays I had no mood/time to write anything, so let's change it with a technical stuff. I was writing a C# code (C# is a programming language copyed from Java) and found a strange behaviour of variable scopes unique to this language. Create a for cycle, define a variable inside, define the same variable after the for cycle and an error is shown:

for (int i = 0; i < 10; i++)
{
int xxx = 1;
}

int xxx = 0; //ERROR!

Variable xxx is already defined in this scope.

What scope, that's a child scope and has nothing to do with this one. Arggg.

:D