私は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 です。基本的に、「User」変数と「Score」変数を PHP スクリプトに POST しようとしています。私が試したスクリプトは次のとおりです。
<?php
$File = "scores.rtf";
$f = fopen($File,'a');
$name = $_POST["name"];
$score = $_POST["score"];
fwrite($f,"\n$name $score");
fclose($f);
?>
「scores.rtf」は変更されません。どんな助けでも大歓迎です。前もって感謝します、私はPHPが初めてです。