I want to make a web request in the main asp.net project. I tried the following, but it doesn't seem to send data to the request:
using System.Net;
...
UTF8Encoding enc = new UTF8Encoding();
string data = "[\"some.data\"]";
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Credentials = new NetworkCredential(user, secret);
Stream dataStream = await request.GetRequestStreamAsync();
dataStream.Write(enc.GetBytes(data), 0, data.Length);
WebResponse wr = await request.GetResponseAsync();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
I do not receive an error message, the request was sent, but it does not send data with the request. I also can not provide the length of the data with the request. Is this a major issue? (ps: credentials are sent correctly)
Can anybody help me?
source
share