简体   繁体   中英

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).

The problem is, they say my script is not set up to handle POST requests.

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?


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.

:(


Thanks, I found http://apikitchen.com/ allows me to properly test it and it's coming back fine. 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?:

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). This is the strPostURL parameter in the last line of the stack trace image you've shown here.

Tell him to use a proper URL when calling SalesForcePost.fncPost and everything should be fine.

This is in no way your fault and doesn't have anything to do with you not handling POST correctly. 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. This may be because he's passing something like "htt://sometest.com" oder "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.

The code you've posted is not his real code, otherwise he would not be getting the "URI scheme not valid" exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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