以下のコードを使用して、この配列string[] str = { "abc" , "sdfsdf" };
値を PHP (Web サービス) に送信しようとしていますが、常に次の出力が得られます
PHPファイルには、実際に配列を受け取り、構造全体を値とともに出力する次のコードがあります。
<?php
$messages = $_POST['messages'];
print_r($messages);
?>
おそらく問題は、送信している配列を PHP が読み取れないことです。C#から送信しているせいかもしれません。
PHP Web サービスがこれを読み取れるように、配列を適切に送信する方法を教えてください。
参考までに: Web サービス側のコードを編集する権限はありません。
私の完全な C# コード
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 = "&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);