title: Send C# array to PHP web service using post
body: <p>I am trying to send this array <code>string[] str = { "abc" ,  "sdfsdf" };</code> value to PHP (web service) using the code below but it is always giving me the following output</p>
  
  <p><img src="https://i.stack.imgur.com/9jPBD.jpg" alt="enter image description here"></p>
  
  <p>In the PHP file I have the following code which actually receives the array and output the total structure with values:</p>
  
  <pre><code>&lt;?php    
    $messages = $_POST['messages'];
    print_r($messages);
  ?&gt;
  </code></pre>
  
  <p>Probably the problem is PHP is unable to read the array I am sending; may be because I am sending it from C#. </p>
  
  <p>Could you please tell me how to send the array properly so that the PHP web service can read this. </p>
  
  <p>FYI: I don't have the authority to edit any code in the web service end.  </p>
  
  <p>My Full C# Code</p>
  
  <pre><code>string[] str = { "num" ,  "Hello World" };
  
  string url = "http://localhost/a/cash.php";
  
  HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create( url );
  
  ASCIIEncoding encoding = new ASCIIEncoding();
  
  string postData ;//= "keyword=moneky";
         postData = "&amp;messages[]=" + str;
  
  byte[] data = encoding.GetBytes(postData);
  
  httpWReq.Method = "POST";
  httpWReq.ContentType = "application/x-www-form-urlencoded";
  httpWReq.ContentLength = data.Length;
  
    using (Stream stream = httpWReq.GetRequestStream())
          {
              stream.Write(data, 0, data.Length);
          }
  
  HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
  
  string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
  
  MessageBox.Show(responseString);
  </code></pre>