0

我正在尝试从 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变量。有没有办法这样做?

4

2 回答 2

0
objWebClient.Headers.Add("Company-Name", value);
于 2013-10-08T18:44:46.167 回答
0

$_SERVER 是一个超全局数组,它返回有关操作环境的信息。您不能动态更改其值。你到底想完成什么?

于 2013-10-08T23:43:45.213 回答