我想發送的字符串我的PHP頁面,我使用的答案中,只有一個網站發送字符串到PHP頁面
C#代碼:
try
{
string url = "http://localhost:8080/test.php";
string str = "test";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
string Data = "message=" + str;
byte[] postBytes = Encoding.ASCII.GetBytes(Data);
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream resStream = response.GetResponseStream();
var sr = new StreamReader(response.GetResponseStream());
string responseText = sr.ReadToEnd();
}
catch (WebException)
{
MessageBox.Show("Please Check Your Internet Connection");
}
和PHP代碼:
if (isset($_POST['message']))
{
$msg = $_POST['message'];
echo $msg;
}
但它只是一個空白頁。 有人可以告訴我什麼是錯?
謝謝。
哪個庫我應該用namevaluecllection? – user3142031
System.Collections.Specialized – Kell
謝謝你的回覆,但它仍然只是一個空白頁 – user3142031