Handy little snippet for testing BizTalk HTTP receive locations.  Logged here for future reference.

	private void HTTPPost(string uri, string message)
            // create the request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.ProtocolVersion = HttpVersion.Version11;
            request.ContentType = "application/soap+xml;charset=UTF-8;";
            request.KeepAlive = false;
            request.Method = "POST";

            // convert message to bytes
            byte[] postBytes = Encoding.ASCII.GetBytes(message);
            request.ContentLength = postBytes.Length;
            Stream requestStream = request.GetRequestStream();

            // send bytes
            requestStream.Write(postBytes, 0, postBytes.Length);

            // get the response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Console.Write(new StreamReader(response.GetResponseStream()).ReadToEnd());
This entry was posted in .NET, BizTalk Server. Bookmark the permalink.

2 Responses to C# HTTP POST Sample

  1. DOT NET SPICE says:

    Reblogged this on DOT NET SPICE.

  2. Johnd340 says:

    Some genuinely prize content on this internet site, bookmarked. beagbkfeaace

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s