I am trying to port the c# cloudinary api to mono and I am having some problems building up the http request.
I have separated out this method for setting up the request but the HttpWebRequest.ContentLength turns out to be -1 in mono, but is .net the content is properly built.
I am running the newest Xamarin Studio on a Mac and I am building a MONO / .NET 4.0 library Mono version: 2.10.12
EDIT: Simplified code, this test passes in Visual Studio but fails in Xamarin studio
EDIT: Code is pushed to github if anybody would like to help
[Test] public void StreamTest() { var request = System.Net.HttpWebRequest.Create("http://foo.com"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; using (var writer = new System.IO.StreamWriter(request.GetRequestStream())) { writer.Write("anything"); } Assert.IsTrue(request.ContentLength > 0); }
WebRequest is an abstract class. The HttpWebRequest class allows you to programmatically make web requests to the HTTP server.
NET 6, the WebRequest, WebClient, and ServicePoint classes are deprecated. The classes are still available, but they're not recommended for new development. To reduce the number of analyzer warnings, only construction methods are decorated with the ObsoleteAttribute attribute.
The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP. Do not use the HttpWebRequest constructor. Use the WebRequest.
When you do
System.Net.HttpWebRequest.Create("http://foo.com");
you actually create an instance of the internal class System.Net.Browser.BrowserHttpWebRequest
Here is the inheritance hierarchy
System.Net.WebRequest
System.Net.HttpWebRequest
System.Net.Browser.PolicyBasedWebRequest
System.Net.Browser.BrowserHttpWebRequest
The content length is handled in PolicyBasedWebRequest, initialized in ctor with -1 and never changed; I suggest you manually set it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With