On Aug 28, 2011, at 11:41 AM, John Murray wrote:
> Sheer bloodymindedness J I found a workaround
> -          Just leave out the headers
> Don t know what would happen if the server objected to this but in this case 
> it works
>  
> Strange that adding headers worked in a straightforward c# Windows app but 
> not in Mono for Android
> The exception code gives some clue that it is in the Mono for android code
>  
> “-                            eee         {System.Net.WebException: An error 
> occurred performing a WebClient request. ---> System.ArgumentException: This 
> header must be modified with the appropiate property.
>   at System.Net.WebHeaderCollection.Add (System.String name, System.String 
> value) [0x00027] in 
> /home/mkestner/monogit/mono/mcs/class/System/System.Net/WebHeaderCollection.cs:167

In short:

        
https://github.com/mono/mono/blob/mono-2-10/mcs/class/System/System.Net/WebHeaderCollection.cs#L167

Because the WebHeaderCollection instance was internally created (i.e. you 
didn't create it, WebClient did), and you're attempting to add a "restricted" 
header, the exception is thrown. What are the restricted headers?

        
https://github.com/mono/mono/blob/mono-2-10/mcs/class/System/System.Net/WebHeaderCollection.cs#L67

This includes Content-Type and Host. As the exception says, the correct 
solution is to instead use the properties, though I'm not sure which properties 
it's referring to.

Alternatively, you could avoid the "internallyCreated" logic:

        var headers = new WebHeaderCollection () {
                { "Content-Type", "application/xml" },
                { "Pragma", "no-cache" },
                { "Cache-Control", "no-cache" },
                { "Host", "www.novlost.eu" },
        };
        var wc = new WebClient {
                Headers = headers,
        };
        // ...
        wc.UPloadData (ss3, "POST", byteArray);

That said, I'm not sure why your code works on .NET and fails on Mono for 
Android. It's also possible that this is a Silverlight-profile related change. 
Could you file a test case?

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to