I struggle again with curl and html parsing. The VIEWSTATE variables are sometimes hard to deal with. Strange enough, php and curl adds +%0A to the end of an urlencoded variable. And as you might guess this poisons the VIEWSTATE mechanism. A workaround that I used is to trim +%0A at the end of urlencoded strings by substr function.