Help with translating a PHP method to C#
<p>Can anyone help? I have a PHP method that sends an http post:</p>

<pre><code>&lt;?php
// API URL
$api_url = "url_of_the_API ";
// Apache auth
$api_user = "user";
$api_pass = "pass";
// Request
$xml = "";
$context = stream_context_create(
array (
'http' =&gt; array(
'method' =&gt; 'POST',
'header' =&gt; sprintf("Authorization: Basic %s\r\n",
base64_encode($api_user.':'.$api_pass))
."Content-type: application/x-www-form-urlencoded\r\n",
'content' =&gt; http_build_query(array('xml' =&gt; $xml)),
'timeout' =&gt; 5,
),
)
);
$response = file_get_contents($api_url,false,$context);
header ("Content-Type:text/xml");
echo $response;
?&gt;
</code></pre>

<p>I need to translate this to C# and I am getting a reply back from the webservice saying "POST call with XML required". I am being told that:</p>

<pre><code>"the XML is not being sent via POST in the 'xml' (name) variable? This is a similar process to submitting a webform with one variable called 'xml'."
</code></pre>

<p>Below is my C#</p>

<pre><code>        // this is where we will send it
        const string uri = "theUri";

        // create a request
        var request = (HttpWebRequest)
        WebRequest.Create(uri); request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.Method = "POST";
        request.Credentials = new NetworkCredential("theUserName", "thePassword");

        // turn our request string into a byte stream
        var postBytes = Encoding.ASCII.GetBytes(postData);

        // this is important - make sure you specify type this way
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = postBytes.Length;
        var requestStream = request.GetRequestStream();

        // now send it
        requestStream.Write(postBytes, 0, postBytes.Length);
        requestStream.Close();

        // grab te response and print it out to the console along with the status code
        var response = (HttpWebResponse)request.GetResponse();
        Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
        Console.WriteLine(response.StatusCode);
</code></pre>
