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
at System.Net.HttpWebRequest.set_Headers (System.Net.WebHeaderCollection
value) [0x0001b] in
/home/mkestner/monogit/mono/mcs/class/System/System.Net/HttpWebRequest.cs:35
3 ...................."
I searched the web and in an unrelated article the author seemed to be
suggesting that in some circumstances one cannot set headers using the Add
method. That led me to eliminate them completely and it worked - let's hear
it for the by guess and by god programmers !!
If anyone knows more I'd be interested in why the c#/ windows thing works
and Mono does not - if only to avoid future pitfalls
John Murray
From: [email protected]
[mailto:[email protected]] On Behalf Of John Murray
Sent: 28 August 2011 11:20
To: 'Discussions related to Mono for Android'
Subject: [mono-android] simple web client crash
Just transported this code from a windows form app testbed - where it is
working fine in same VS2010 debugger
Can anyone tell me - should I be handling things differently in mandroid?
It simply hangs on the line Wc.Uploaddata() and I cant get a clue what's
causing it
Obviously I've checked connection etc
string mystr2 = "<nwx
version=\"0.3.5\"><Request id=\"1\"><AvailableEpochs/></Request></nwx>";
WebClient wc = new WebClient();
wc.Headers.Add("Content-Type", "application/xml");
wc.Headers.Add("Pragma", "no-cache");
wc.Headers.Add("Cache-Control", "no-cache");
wc.Headers.Add("Host", "www.navlost.eu");
string ss3 = "http://navlost.eu/nwxs/";
byte[] byteArray = Encoding.ASCII.GetBytes(mystr2); //(mystr2
is a string representation of xml file
byte[] responseArray = wc.UploadData(ss3, "POST", byteArray);
I'm stumped
Any help gratefully solicited
John Murray
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid