S
Steven
Is there something I'm missing that needs to be in a web.config or
something?
I have a simple test application trying to track down a problem.
I create an httplistener on one side:
//Server
HttpListener hl = new HttpListener();
hl.Prefixes.Add("http://ip:7867/test/");
hl.Start();
IAsyncResult result = hl.BeginGetContext(new
AsyncCallback(HttpListenerCallback), hl);
private static void HttpListenerCallback(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.ContentType = "text/plain";
string text = "Successful post";
response.ContentLength64 = text.Length;
response.OutputStream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(text),
0, text.Length);
response.OutputStream.Close();
result = listener.BeginGetContext(new
AsyncCallback(HttpListenerCallback), listener);
}
And then consume it on the other side:
//client
static void Main(string[] args)
{
try
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://ip:7867/test/");
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = 0;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader strm = new StreamReader(response.GetResponseStream());
string output = strm.ReadToEnd();
Console.Write(output);
strm.Close();
}
catch (Exception ex)
{
Console.Write("Error: " + ex.Message);
}
Console.ReadKey();
}
The ports are definitely open, hyperterminal can communicate back and forth
as long as the sample isn't running, so no firewall issues or anything like
that. If IP is localhost or anything on the same network, everything works
fine, but as soon as I change it to a WAN address and try to hit it remotely
I get "400 Bad Request" in a WebException. So why is it rejecting the
remote request when it comes in over the WAN?
Thanks!
something?
I have a simple test application trying to track down a problem.
I create an httplistener on one side:
//Server
HttpListener hl = new HttpListener();
hl.Prefixes.Add("http://ip:7867/test/");
hl.Start();
IAsyncResult result = hl.BeginGetContext(new
AsyncCallback(HttpListenerCallback), hl);
private static void HttpListenerCallback(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.ContentType = "text/plain";
string text = "Successful post";
response.ContentLength64 = text.Length;
response.OutputStream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(text),
0, text.Length);
response.OutputStream.Close();
result = listener.BeginGetContext(new
AsyncCallback(HttpListenerCallback), listener);
}
And then consume it on the other side:
//client
static void Main(string[] args)
{
try
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://ip:7867/test/");
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = 0;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader strm = new StreamReader(response.GetResponseStream());
string output = strm.ReadToEnd();
Console.Write(output);
strm.Close();
}
catch (Exception ex)
{
Console.Write("Error: " + ex.Message);
}
Console.ReadKey();
}
The ports are definitely open, hyperterminal can communicate back and forth
as long as the sample isn't running, so no firewall issues or anything like
that. If IP is localhost or anything on the same network, everything works
fine, but as soon as I change it to a WAN address and try to hit it remotely
I get "400 Bad Request" in a WebException. So why is it rejecting the
remote request when it comes in over the WAN?
Thanks!