Error CS1061: 'HttpWebRequest' does not contain a definition for 'ContentLength'
I'm currently working on a project that has a hololens communicating to a device on a http-server via json post-requests. And all is working fine, until I want to post more than a command to the server, at which point I open up a stream and write to it, so far so good. But as I can't set the content-length, the method crashes in holo and I get the error "Generic error: do you have the right content-length?"
Therefore I tried altering the content-length, based on this documentation I should be able to set the ContentLength property. When typing it out in Visual Studios (2017) I get the suggestion to add .ContentLength to alter the property.
But upon building in unity I get the above error. I work in Unity 2018.4.10f1 as most everything is really version-sensitive.
The request in itself is created as such:
internal HttpWebRequest CreateRequest(object obj = null)
{
var basicRequest = (HttpWebRequest)WebRequest.Create(URL);
basicRequest.Method = Verb;
basicRequest.CookieContainer = CookieContainer;
basicRequest.ContentType = "application/json";
if (obj is string)
basicRequest.ContentLength = obj.ToString().Length;
return basicRequest;
}
.
error CS1061: 'HttpWebRequest' does not contain a definition for 'ContentLength' and no accessible extension method 'ContentLength' accepting a first argument of type 'HttpWebRequest' could be found (are you missing a using directive or an assembly reference?)