1
我正在嘗試構建一個C#表單應用程序與我的php網頁進行交互。它使HTTP文件發佈到PHP頁面,但PHP頁面期望一個數組。Http php中的C#數組#
如果我在PHP,而不是C#這樣做好像:(它的工作原理)
<?php
$postArray=array("a"=>"1","b"=>"2","c"=>3);
....
curl_setopt($curl,CURLOPT_POSTFIELDS,$postArray);
...
?>
C#代碼:(不工作)
string boundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("localhost/index.php");
webrequest.CookieContainer = cookies;
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";
webrequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; tr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
webrequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
NameValueCollection n1 = new NameValueCollection();
n1.Add("a", "1");
n1.Add("b", "2");
n1.Add("c", "3");
using (var requestStream = webrequest.GetRequestStream())
using (var writer = new StreamWriter(requestStream))
{
writer.Write("POST_DATA=" + n1);
}
using (var responseStream = webrequest.GetResponse().GetResponseStream())
using (var reader = new StreamReader(responseStream))
所以,我怎樣才能發佈此PHP數組在C#中?我嘗試了哈希表和字典,但有些東西是錯誤的。請幫幫我。謝謝。
顯示你的c#代碼,你有(甚至不工作) – Andrey 2011-02-06 19:29:46