From: Steven on
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!


From: Peter Duniho on
Steven wrote:
> [...]
> 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?

You've already answered your question: everything works fine if you're
on the same network. So there's nothing wrong with your program. You
just need to fix your network configuration so that connection requests
from the WAN side make it back to your HTTP server (listener).

Pete
From: Steven on
> Steven wrote:
>> [...]
>> 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?
>
> You've already answered your question: everything works fine if you're on
> the same network. So there's nothing wrong with your program. You just
> need to fix your network configuration so that connection requests from
> the WAN side make it back to your HTTP server (listener).
>
> Pete

But what is there to fix? As I also mentioned, if I listen in hyperterminal
on that same server and open hyperterminal from the same place I run the
client program, they connect (using the same port as the program) and I can
see my characters go back and forth from either side, so all the ports are
configured correctly on the network. Is there some other network
configuration you're referring to that I'm not aware of if the ports are
communicating successfully?


From: Steven on
> Steven wrote:
>> [...]
>> 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?
>
> You've already answered your question: everything works fine if you're on
> the same network. So there's nothing wrong with your program. You just
> need to fix your network configuration so that connection requests from
> the WAN side make it back to your HTTP server (listener).
>
> Pete

One more thing strikes me about it. I'm getting back a 400 -Bad Request,
that implies it's answering. SOMETHING is sending back the error code, so
it's like the httplistener is saying, "Nope, I can't do remote requests",
and returning the error.


From: Steven on
>> [...]
>> 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?
>
> You've already answered your question: everything works fine if you're on
> the same network. So there's nothing wrong with your program. You just
> need to fix your network configuration so that connection requests from
> the WAN side make it back to your HTTP server (listener).
>
> Pete

Okay, here's the odd thing, I changed the prefix to a wildcard:
hl.Prefixes.Add("http://*:7867/test/");
and it's now accepting the requests, so I looked at the request and the uri
of the request matched exactly what I had in the prefix when it was failing.
Very strange!


 | 
Pages: 1
Prev: Emacs emu mode for VS2010
Next: Checking for True