Sending a XML string from C# app in PPC



HI,

I am sending a simple xml string ( u can see it in the code) to a PHP
script on a server from a C# app. However its not receiving it all .
PHP script dumps everything I send to it back to me. When I send the
data thru a HTML form with the same string I get the correct output.

for instance
string is : <order><product>mens polo</product><price>4.89</
price><size>large</size></order>
HTML output I get: 1Array ( [hiddenbx] => mens polo4.89large )
My app gets 1Array(\n\n\n)

1 is for receiving some data.

Most likely I am not sending the data in the right form. Any help
will be really appreciated.

Thanks
SS

Here's my code

// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("A php url") as
HttpWebRequest;
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "<order><product>mens polo</
product><price>4.89</price><size>large</size></order>";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "text/xml";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = null;
try
{
dataStream = request.GetRequestStream();
}
catch (WebException we)
{
MessageBox.Show(we.ToString(), "Request error");
strStatus = "Request Error";
return bSuccess;
}
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = null;
try
{
response = request.GetResponse()as HttpWebResponse;
}
catch (System.Exception we)
{
MessageBox.Show(we.ToString(), "Response error");
strStatus = "Response Error";
return bSuccess;
}
// Display the status.
strStatus = ((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.
MessageBox.Show(responseFromServer);
bSuccess = true;
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
.



Relevant Pages

  • Re: HttpWebRequest.GetRequestStream times out
    ... When I encounter this exception, this is printed in the log: ... Stream sendStream = httpReq.GetRequestStream; ... you never read more than 1 kB of the response, ... The request timeout is set to 100 seconds, and the requests that time out ...
    (microsoft.public.dotnet.framework.performance)
  • Re: problem WebRequest and WebResponse
    ... the Stream and the WebResponse instances. ... HttpWebRequest request = ... WebResponse response = null; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: NotificationSampleWebDav-Monitor OWA Inbox
    ... re-login or update your cookie with each response you get... ... Warning: Exiting Action with an exception: The remote server returned an ... // Create request object and assign credentials. ... Stream newStream = Request.GetRequestStream; ...
    (microsoft.public.exchange.applications)
  • Re: WebDAV mark as read?
    ... I am using following code to change the message read/unread status. ... // Add the network credentials to the request. ... Stream QueryStream = HttpWRequest.GetRequestStream; ... // Send Request and Get Response ...
    (microsoft.public.exchange.applications)
  • Re: Close OWA Connection
    ... established my connection to OWA to terminate the connection?!? ... HttpWebRequest request; ... HttpWebResponse response; ... Stream stream; ...
    (microsoft.public.exchange.development)