我正在尝试从 C# 向 php 网页提交发布请求。php 查询如下所示:
$result = mysql_query ("INSERT INTO SomeTable (ID, NAME, PERIOD, INFO, REQUESTED_BY,
DATE) " ." values (" . $id . ", '" . $_POST['Name'] . "', '" . $_POST['Period'] ."', '" .
$_POST['Info'] . "', '" . $_SERVER['HTTP_MYCOMPANY_EMAIL'] . "', '".date( 'Y-m-d
H:i:s')."')");
如您所见,其中一个变量是$_SERVER['HTTP_MYCOMPANY_EMAIL']
我要传递的。我无法冒充身份,因为此代码将从工作流中执行。
这是我的 C# 代码,如下所示:
WebClient objWebClient = new WebClient();
NameValueCollection objNameValueCollection = new NameValueCollection();
objNameValueCollection.Add("Name", "test123");
objNameValueCollection.Add("Period", "30 Days");
objNameValueCollection.Add("Info", "someinfo");
objNameValueCollection.Add("HTTP_MYCOMPANY_EMAIL", "fname_lname");
objWebClient.UseDefaultCredentials = true;
try
{
byte[] bytes = objWebClient.UploadValues("https://www.someweb.com/phpPage.php", "POST", objNameValueCollection);
Console.Write(Encoding.ASCII.GetString(bytes));
Console.WriteLine();
Console.WriteLine("Press any key to exit");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
我可以设置$POST
变量的值,但不能设置$SERVER
变量。有没有办法这样做?