我对 PHP 比较陌生,我正在尝试运行一个小脚本。我有一个使用以下函数发布数据的 VB .net 程序。
Public Sub PHPPost(ByVal User As String, ByVal Score As String)
Dim postData As String = "user=" & User & "&" & "score=" & Score
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://myphpscript"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.ContentLength = byteData.Length
Dim postReqStream As Stream = postReq.GetRequestStream()
postReqStream.Write(byteData, 0, byteData.Length)
postReqStream.Close()
End Sub
其中“myphpscript”实际上是 PHP 脚本的完整 URL。基本上我正在尝试将“用户”变量和“分数”变量发布到 PHP 脚本。我试过的脚本如下:
<?php
$File = "scores.rtf";
$f = fopen($File,'a');
$name = $_POST["name"];
$score = $_POST["score"];
fwrite($f,"\n$name $score");
fclose($f);
?>
“scores.rtf”没有改变。任何帮助,将不胜感激。提前感谢,我是 PHP 新手。