将 HttpListenerRequest 发送到另一个网站
Send HttpListenerRequest to another website
我正在尝试将收到的 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)
但我不能发送 context.Request
作为 HttpContent
:(
希望我提供了足够的信息。
代码看起来像这样:
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();
我正在尝试将收到的 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)
但我不能发送 context.Request
作为 HttpContent
:(
希望我提供了足够的信息。
代码看起来像这样:
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();