Hey im trying to post an http request (Create Teams online meeting) to the Graph API under c# .Net Framework 4.0 so i cannot use the Graph-SDK and i cannot use the System.net.http libary (no httpClient). I tried HttpWebRequest but im having difficulties with posting Json to the API.
My Request Function looks like this:
private string SendHttpRequest(string Method, string ContentType, WebHeaderCollection Headers, string Content, string URI)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.Method = Method;
request.Headers = Headers;
request.PreAuthenticate = true;
request.ContentType = ContentType;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
requestWriter.Write(Content);
requestWriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseStream = response.GetResponseStream();
StreamReader responseReader = new StreamReader(responseStream);
string responseText = responseReader.ReadToEnd();
responseReader.Close();
return responseText;
}
catch (Exception ex)
{
throw (ex);
}
}
And this works fine when my Content Type is text/xml(for a diffrent API) but not if its Application/Json.
I always get an Error 400 when i call HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Method = "POST"
ContentType = "application/json"
Headers = Headers.Set(HttpRequestHeader.Authorization, "Bearer " + accessToken);
Content = string jsonContent = JsonConvert.SerializeObject(Content);
URI = "https://graph.microsoft.com/v1.0/me/onlineMeetings"