Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WebRequest POST参数无法通过_C#_Post_Parameters_Webclient - Fatal编程技术网

C#WebRequest POST参数无法通过

C#WebRequest POST参数无法通过,c#,post,parameters,webclient,C#,Post,Parameters,Webclient,我正在尝试使用C#中的WebClient发布到网页。 不知怎的,参数没有通过。 页面本身是一个php页面。 我已经用常规浏览器/html页面测试了同一个页面,然后它就工作了,所以我认为这是一个客户端问题 谁能告诉我我可能做错了什么 WebClient myClient = new WebClient(); myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

我正在尝试使用C#中的WebClient发布到网页。 不知怎的,参数没有通过。 页面本身是一个php页面。 我已经用常规浏览器/html页面测试了同一个页面,然后它就工作了,所以我认为这是一个客户端问题

谁能告诉我我可能做错了什么

        WebClient myClient = new WebClient();
        myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        try
        {
            NameValueCollection keyvaluepairs = new NameValueCollection();
            keyvaluepairs.Add("request", "foo");
            byte[] responseArray = myClient.UploadValues("http://www.motio.com/test.php?id=7", "POST", keyvaluepairs);
            string response = Encoding.ASCII.GetString(responseArray);
        }
        catch (Exception e)
        {
        }

您是否尝试使用GET而不是POST来确认web请求本身是否有问题?

很抱歉占用您的时间。经过进一步调查,我使用的url使用的是http,服务器将我重定向到http,丢失了post变量。

您忽略了任何异常,因此如果出现问题,您将看不到它。请在您的计算机上安装findler,看看发生了什么,您是否正确。但是,实际的代码不会这样做。我做到了。我看到测试的结果仍然在上面发布的uri中;get('id')参数正在通过。