我正在尝试使用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)
{
}
答案 0 :(得分:0)
您是否尝试过GET而不是POST,以确保Web请求本身有问题?
答案 1 :(得分:0)
我很抱歉占用你的时间。经过进一步调查,结果发现我使用的网址是使用http,服务器将我重定向到http,丢失了帖子变量。