我正试图将收到的http请求转发到另一个网站,下面是我如何接收数据的方法。
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:3294/discord/");
listener.Start();
while (true)
{
Console.WriteLine("Listening...");
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
//here is want to send data to https://www.discord.com/api/webhooks/#################/###########
}要发送数据,我使用HttpClient.PostAsync(string requestUri, HttpContent content),但不能以HttpContent的形式发送context.Request:
我希望我能提供足够的信息。
发布于 2021-04-05 18:11:15
代码如下所示:
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:3294/discord/");
listener.Start();
Console.WriteLine("Listening...");
HttpListenerContext context = listener.GetContext();
Stream body = context.Request.InputStream;
Encoding encoding = context.Request.ContentEncoding;
byte[] buffer = new byte[body.Length];
body.Read(buffer,0,(int)body.Length);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("https://www.discord.com/api/webhooks/#################/###########");
request.Method = "POST";
request.ContentType = context.Response.ContentType;
body.Position = 0;
request.ContentLength = body.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();https://stackoverflow.com/questions/66955921
复制相似问题