I am using the below code which I got from MSDN to send an XML Data via HTTP Post to a server running a PHP script. I receive a response from the server but it does not recieve my XML data.
The response I get is that no XML data is received by the PHP script. I tried changing my encoding to UTF8 but it did not change anything. I am using .NET 4.0
Any hints or tips will be greatly appreciated.
Code:using System; using System.IO; using System.Net; using System.Text; namespace Examples.System.Net { public class WebRequestPostExample { public static void Main() { // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create("http://stage05.fujifilmimagine.com/phototellerphp/job_tracking.php"); // Set the Method property of the request to POST. request.Method = WebRequestMethods.Http.Post; // Create POST data and convert it to a byte array. string postData = "<XML><JOB_NO>JOB~AAA012238</JOB_NO><JOB_STATUS_ID>21</JOB_STATUS_ID><STATUS_DESCRIPTION>Has been downloaded</STATUS_DESCRIPTION></XML>"; byte[] byteArray = Encoding.ASCII.GetBytes(postData); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream and send it now dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. Console.WriteLine(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); Console.ReadLine(); } } }


Reply With Quote

Bookmarks