使用.NET WebClient类提交时,PHP中未收到POST值 [英] POST values not received in PHP when submitted with .NET WebClient class

查看:49
本文介绍了使用.NET WebClient类提交时,PHP中未收到POST值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过.NET WebClient类发送一些POST数据,如下所示:

I'm trying to send some POST data with the .NET WebClient class as following:

WebClient objWebClient = new WebClient();

NameValueCollection objNameValueCollection = new NameValueCollection();
objNameValueCollection.Add("variable1", value1);
objNameValueCollection.Add("variable2", value2);
objNameValueCollection.Add("variable3", value3);

byte[] bytes = objWebClient.UploadValues(objURI, "POST", objNameValueCollection);
MessageBox.Show(Encoding.ASCII.GetString(bytes));

但是当我用PHP打印POST值时

But when I print the POST values in PHP with

var_dump($_POST)

我将得到一个空字符串.

I'll get an empty string.

我在这里做错了什么?为什么POST值显然没有提交给PHP脚本?

What I'm doing wrong here? Why are the POST values obviously not submitted to the PHP script?

预先感谢您的任何想法安德烈亚斯(Andreas)

Thanks in advance for any ideas Andreas

推荐答案

我现在自己找到了解决方案,只想分享结果.

I've found the solution myself now and just want to share the result.

这与我的代码本身无关.问题是我已将重定向添加到我的Apache配置中,以重定向来自域 www.ab-tools的所有请求.de www.ab-tools.com .

It had nothing to do with my code itself. The problem was that I've added a redirect to my Apache configuration to redirect all requests from my domain www.ab-tools.de to www.ab-tools.com.

但是.NET应用程序仍然将数据发布到旧域下的脚本中.

But the .NET application still posted the data to a script below the old domain.

由于重定向删除了所有POST数据,因此脚本没有从.NET应用程序中获取数据.

As a redirect drops all POST data, the script did not get the data from the .NET application.

那确实是一个愚蠢的错误-我花了一段时间才明白这一点.;-)

That was really a stupid mistake - it took me a while till I understood that. ;-)

最诚挚的问候,并再次感谢您的所有答复安德烈亚斯(Andreas)

Best regards and thanks again for all replies Andreas

这篇关于使用.NET WebClient类提交时,PHP中未收到POST值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆