简体   繁体   English

如何从.NET脚本接收POST数据

[英]How to receive POST data from a .NET script

I am working with a company who has made a script to send over POST data to my PHP script (which is all setup and port forwarded properly etc). 我正在与一家公司合作,该公司制作了一个脚本,将POST数据发送到我的PHP脚本(所有设置和端口正确转发等)。

The problem is, they say my script is not set up to handle POST requests. 问题是,他们说我的脚本没有设置为处理POST请求。

This is their script: 这是他们的脚本:

Try 尝试

        strPost = strPost.Trim.Replace(" ", "%20")



        Dim objRequest As HttpWebRequest = WebRequest.Create(strPostURL)

        objRequest.Method = "POST"

        objRequest.ContentLength = strPost.Length

        objRequest.ContentType = "application/x-www-form-urlencoded"



        Try

            myWriter = New StreamWriter(objRequest.GetRequestStream())

            myWriter.Write(strPost)

        Catch eg As Exception



        Finally

            myWriter.Close()

        End Try



        Dim objResponse As HttpWebResponse = objRequest.GetResponse()

        Dim sr As StreamReader

        sr = New StreamReader(objResponse.GetResponseStream())

        success = sr.ReadToEnd()

        sr.Close()



        success = "Post Successful"



    Catch ex As Exception

        success = ex.ToString

    End Try

And here is mine: 这是我的:

<?PHP

$website = $_POST['web'] ;
$name = $_POST['name'] ;
$tel = $_POST['tel'] ;
$town = $_POST['town'] ;

foreach($_POST as $key => $thisOne){
$out .= $key . ': ' . $thisOne ;
}
if($out)
mail('test@test.com', 'Test', $out) ;
?>

I am unsure of what they mean by my script is not set up to handle POST data, as $_POST is the right thing to use no? 我不确定他们的意思是什么,我的脚本没有设置来处理POST数据,因为$ _POST是正确的用法没有?


Thanks for your reply, that is what I thought, but he is adimant that my script is faulty. 谢谢你的回复,这就是我的想法,但他很高兴我的脚本有问题。

This is the error he says he is getting: 这是他说他得到的错误:

.NET错误


He is telling me he still gets that error and: 他告诉我他仍然得到了这个错误:

The code we use works with Sales Force, Sage and 7 other custom CRM integrations we have previously done. 我们使用的代码与Sales Force,Sage以及我们之前完成的其他7个自定义CRM集成一起使用。

:( :(


Thanks, I found http://apikitchen.com/ allows me to properly test it and it's coming back fine. 谢谢,我发现http://apikitchen.com/允许我正确测试它,它回来了。 Thanks for your help! 谢谢你的帮助! Must be him like you say. 一定是他就像你说的那样。


He is now telling me he is getting a new error! 他现在告诉我他正在收到新的错误!

在此输入图像描述


He has just sent me the following, can anyone with .NET experience see anything wrong with the code?: 他刚给我发了以下信息,任何有.NET经验的人都可以看到代码有什么问题吗?:

Try
strPost = "name=lf&town=london&country=uk&web=www.lf.com&tel=0123456789&keywords=sales&pages=5&multivisit=multihitdt=2012/04/30%2014:31referrer=google&landing=home"

        strPost = strPost.Trim.Replace(" ", "%20")



        Dim objRequest As HttpWebRequest = WebRequest.Create("http://mysite.dyndns-remote.com/myscript.php")

        objRequest.Method = "POST"

        objRequest.ContentLength = strPost.Length

        objRequest.ContentType = "application/x-www-form-urlencoded"



        Try

            myWriter = New StreamWriter(objRequest.GetRequestStream())

            myWriter.Write("name=lf&town=london&country=uk&web=www.lf.com&tel=0123456789&keywords=sales&pages=5&multivisit=multihitdt=2012/04/30%2014:31referrer=google&landing=home")

        Catch eg As Exception



        Finally

            myWriter.Close()

        End Try



        Dim objResponse As HttpWebResponse = objRequest.GetResponse()

        Dim sr As StreamReader

        sr = New StreamReader(objResponse.GetResponseStream())

        success = sr.ReadToEnd()

        sr.Close()



        success = "Post Successful"



    Catch ex As Exception

        success = ex.ToString

    End Try

The URI he's passing to the web request doesn't seem to be valid (the Exception says it is empty). 他传递给Web请求的URI似乎没有效果(Exception表示它是空的)。 This is the strPostURL parameter in the last line of the stack trace image you've shown here. 这是您在此处显示的堆栈跟踪图像的最后一行中的strPostURL参数。

Tell him to use a proper URL when calling SalesForcePost.fncPost and everything should be fine. 告诉他在调用SalesForcePost.fncPost时使用正确的URL,一切都应该没问题。

This is in no way your fault and doesn't have anything to do with you not handling POST correctly. 这绝不是您的错,也与您没有正确处理POST有任何关系。 It is his fault. 这是他的错。 Tell him so, and if he doesn't believe you, send him here to show us some code. 告诉他,如果他不相信你,请把他送到这里给我们看一些代码。

EDIT 编辑
As for the new error: Same thing here. 至于新错误:这里也是一样的。 He's not passing a valid URI string. 他没有传递有效的URI字符串。 This may be because he's passing something like "htt://sometest.com" oder "http:/sometest.com". 这可能是因为他传递的内容类似于“htt://sometest.com”或“http:/sometest.com”。 We can't help you any further unless you post all code necessary to see how the fncPost method is called and most of the code of the fncPost method - at least the part where he creates the web request. 除非您发布所有必要的代码怎么看我们能不能帮助您任何进一步fncPost方法被调用和大多数的代码fncPost至少在那里,他将创建Web请求的部分-方法。

The code you've posted is not his real code, otherwise he would not be getting the "URI scheme not valid" exception. 您发布的代码不是他的真实代码,否则他不会得到“URI方案无效”异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM