Oh no!

You are using a old browser, many things won't work properly in it. Plase save developers the pain to support old-crappy-browsers, please upgrade.

Get new Firefox, Internet Explorer or any other modern browser.

...other websites you've been visiting will look better too :)

ServerProtocolViolation with Http Basic on

I had a strange problem with my mobile application when we turned on Basic authentication on the http server. W32 version seems to work OK, but the same code ran Windows Mobile 5 with .NET CF throws: WebException with Status=ServerProtocolViolation.

Normally when a http server needs authorization, it responds with 401 Unauthorized then the client re-sends a request with proper Authorization header. In my case, .NET CF did not understood servers response, claiming that: The server response was not a valid HTTP response.

Request:

POST /X HTTP/1.1
Content-Type: text/xml
User-Agent: X
Content-Length: 384
Connection: Keep-Alive
Expect: 100-continue
Host: 217.X.X.X:Y

[...]

Response:

HTTP/1.1 401 Unauthorized
Server: X
WWW-Authenticate: Basic realm=X

Method POST requires a valid user name and password

Here client throws a WebException with Status=ServerProtocolViolation.

My solution was to present Authorization on the first request, since I know it will be needed. Since it solved the problem, I did not investigate strange Expect: 100-continue header, maybe it was the problem source. Oh and another thing, when server is more forthcoming and returns Connection: close and Content-Length: X headers the CF versions also works fine.

Anyway if you would need to create Authorization header yourself:

public static void SetBasicAuthorization(WebRequest request, string user,string password) { string authorization = user + ":" + password; byte[] bytes = Encoding.Default.GetBytes(authorization); authorization = Convert.ToBase64String(bytes); request.Headers.Add("Authorization", "Basic " + authorization); }

Read more...

No Preamble for UTF8Encoding

If you ever need to write something to a stream without preamble for eg. "" in UTF8 encoding, try to use:

UTF8Encoding encoding = new UTF8Encoding(false, true);

instead of default:

UTF8Encoding encoding = Encoding.UTF8;

Read more...

About

This site is a personal experiment of mine.

Although I have little spare time, because of my work, family and friends duties (you know: Work hard, play hard... shop for things to eat), I wanted to share an write down some thoughts that are going through my mind. I do not expect anyone to read this stuff, I do it mostly for my selfish, narcissistic self ;).

For starters. I keep a lot of notes and knowledge base like stuff, in a few places, emails, Google notebook, bookmarks. I wanted to organize them and keep them for future use, so I won't repeat mistakes. If keepeing them here will help someone else, that's great!

I'm a lazy type of a person, I heard that's the inventor kind, also I'm a Trekkie (what programmer geek isn't), so I'd wish for the world to be a better place. Because of that I sometimes have and idea about things that could make life simpler. I bet some of this stuff was/will be invented by someone else but still they where also my original ideas. I have decided to blog them down.

About the author

My name is Janusz Skonieczny. I live in Warsaw, Poland.

I am a programmer by heart. Currently I hold a CTO position in a Polish small software company, Qualent Software.

I have almost 7 years of experience working in IT, most of this time I worked as a professional developer. I have experience in Enterprise Java and Microsoft .NET. I have worked on and lead project teams designing, developing and deploying software solutions in most of Polish telecommunication providers and biggest banks.

I like Agile Development direction. I cannot say that everything I do is agile, but I certainly use a few practices in my every day work.

For a couple of years I have specialized in Microsoft .NET and C# development - all kinds and flavours: Win Forms, ASP.NET, Mobile. Enterprise IT Infrastructure is the business area that I mostly do stuff. Identity Management & Administration is the area that often keeps coming back.

For last 3 years I was holding CTO position in a small software companies (at first informally ;)). In Internetium I have designed and introduced a software production process, deployed tools to support that process and trained developers to use them smoothly, it was then ISO 9001:2000 certified.

My area of professional interest is software quality, development automation, reliable and repeatable process, team motivation and other things that are related to project management.

I hold various certificates:

  • Sun Certified Programmer for the Java 2 Platform (SCJP).
  • Microsoft Certified Solution Developer (MCSD) for Microsoft .NET
  • Microsoft Certified Application Developer (MCAD) for Microsoft .NET
  • Microsoft Certified Database Administrator (MCDBA) for Microsoft SQL Server 2000
See my MCP transcript (685415, VBGT54rf).

If you wish you can see my LinkedIn profile to see my professional and educational history.

Read more...