0
votes

I'm trying to use the HttpWebRequest class to send a request to my server to retrieve some data, but the .ContentLength propertly isnt available to me, though in any other C# app (Winforms, Console) it is...

I've looked for so many answers and I just cannot find something that works

The project: Xamarin.Forms (Portable Class Library) for multi platforms

Full error:

Severity Code Description Project File Line Suppression State Error CS1061 'HttpWebRequest' does not contain a definition for 'ContentLength' and no extension method 'ContentLength' accepting a first argument of type 'HttpWebRequest' could be found (are you missing a using directive or an assembly reference?)

1

1 Answers

0
votes

If you want to use the HttpWebRequest contentLength property in Xamarin Forms you can access it via DependencyService you will come to find some things are just not available in the xamarin portable library you can find more info on that here

So In Your Portable Library create a interface example below

public interface IMyspace
{
   string result(string url);
}

Then In Your Actual Android Or IOS or whatever Project create a class inheriting your interface

public class MyClass : IMyspace
{    
    public string result(string url)
    {
      var target = new System.Uri(url);
      var httpRequest = (HttpWebRequest) HttpWebRequest.Create(target);
        //do whatever stuff you trying to do here and just return  
          whatever you want 
    }
}