Error while attempting to simulating an http post containing XML on localhost

206 Views Asked by At

I'm sure this is simple, but I'm missing the forest for the trees...

I need to simulate an HTTP Post to my localhost so I can test some response and request routines to ensure that I'm receiving and sending the XML required correctly. After some research, I thought it would be a good idea to use WebClient.UploadString to accomplish this.

Basically, I need to send an HTTP Post in which the InputStream contains an XML document.

The method code I'm using is:

public static void SendPunchOutSetupRequestTest()
  {
    string xml = File.ReadAllText(
                @"C:\blah\blah\blah\Sample XML\PunchoutSetupRequest.xml");

    string url = new UriBuilder("http", "localhost", 2020,"Account\\CCLaunch").ToString();

    using (WebClient client = new WebClient())
      {
          client.UploadString(url, xml);
      }
 }

When I hit the client.UploadString() portion, I'm getting the error: "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

I'm not exactly sure what is happening or why. I should mention that I'm running the method above within the same web app that I'm trying to debug (the post is going to localhost:2020/Account/someView). Is the problem the fact that I'm calling a page (using client) from within the same application that the page exists?

If I'm NOT going about this correctly, can anyone make any suggestions as to how I can send an HTTP Post to Localhost where the inputstream contains a static (for now) XML?

0

There are 0 best solutions below