locked
Unable to post properly RRS feed

  • Question

  • User944339287 posted

    Hi guys.. i wonder what's wrong to my post form method.

    My form will post to
    http://localhost:49260/viewcart/​​https://securepay.xxxxxx.com/PAY/Payment.aspx 
    instead of ​​
    https://securepay.xxxxxx.com/PAY/Payment.aspx

    Any idea?

    Imports System.Web
    Imports System.Collections.Specialized
    Imports System.Net
    
    Partial Public Class RemotePostPayment
        Private inputValues As NameValueCollection
    
        Public Property Url() As String
            Get
                Return m_Url
            End Get
            Set(ByVal value As String)
                m_Url = value
            End Set
        End Property
    
        Private m_Url As String
    
        Public Property Method() As String
            Get
                Return m_Method
            End Get
            Set(ByVal value As String)
                m_Method = value
            End Set
        End Property
        Private m_Method As String
    
        Public Property FormName() As String
            Get
                Return m_FormName
            End Get
            Set(ByVal value As String)
                m_FormName = value
            End Set
        End Property
    
        Private m_FormName As String
    
        Public ReadOnly Property Params() As NameValueCollection
            Get
                Return inputValues
            End Get
        End Property
    
        Public Sub New()
    
            inputValues = New NameValueCollection()
    
            Url = "​​https://securepay.xxxxxx.com/PAY/Payment.aspx"
    
            Method = "post"
            FormName = "ePayment"
    
        End Sub
    
        Public Sub Add(ByVal name As String, ByVal value As String)
            inputValues.Add(name, value)
        End Sub
    
        Public Sub Post()
            Dim context = HttpContext.Current
            context.Response.Clear()
            context.Response.Write("<html><head>")
            context.Response.Write(String.Format("</head><body onload=""document.{0}.submit()"">", FormName))
            context.Response.Write(String.Format("<form name=""{0}"" method=""{1}"" action=""{2}"" >", FormName, Method, Url))
            For i As Integer = 0 To inputValues.Keys.Count - 1
                context.Response.Write(String.Format("<input name=""{0}"" type=""hidden"" value=""{1}"">", HttpUtility.HtmlEncode(inputValues.Keys(i)), HttpUtility.HtmlEncode(inputValues(inputValues.Keys(i)))))
            Next
            context.Response.Write("</form>")
            context.Response.Write("</body></html>")
            context.Response.[End]()
        End Sub
    
    End Class




        Private Sub payment()
    
            Dim myPost As New RemotePostPayment
            myPost.Add("TransactionType", TransactionType)
            myPost.Add("PymtMethod", PymtMethod)
            myPost.Add("ServiceID", ServiceID)
            myPost.Add("PaymentID", PaymentID)
            myPost.Add("OrderNumber", OrderNumber)
            myPost.Add("PaymentDesc", PaymentDesc)
            myPost.Add("MerchantName", MerchantName)
            myPost.Add("MerchantReturnURL", MerchantReturnURL)
            myPost.Add("Amount", Amount)
            myPost.Add("CurrencyCode", CurrencyCode)
            myPost.Add("CustIP", CustIP)
            myPost.Add("CustName", CustName)
            myPost.Add("CustEmail", CustEmail)
            myPost.Add("CustPhone", CustPhone)
            myPost.Add("MerchantCallBackURL", MerchantCallBackURL)
            myPost.Add("HashValue", HashedStr)
            myPost.Add("LanguageCode", LanguageCode)
            myPost.Add("PageTimeout", PageTimeout)
    
            myPost.Post()
    
        End Sub
    



    Wednesday, March 18, 2020 7:17 AM

All replies

  • User753101303 posted

    Hi,

    An absolute url should work. For example :

    <form action="https://forums.asp.net/">
       <input type="submit">
    </form>	

    does show this site once the button is clicked. Double check the generated markup and the value you have the action attribute.

    Wednesday, March 18, 2020 12:46 PM
  • User475983607 posted

    There is no indication in the code snippet where the private payment() method is called which then invokes the Post() Sub.  Please take a few moments to run your code your the Visual Studio debugger.   Set a break point and verify the variables contain expected values.

    IMHO, it is a bit dangerous to use the HTTP Context in a non web page class.  This type of design can lead to confusing coding issues because the class must be invoked during a request.  I recommend passing the Http Context to the RemotePostPayment class constructor to ensure the context is not empty.  Or better yet drop the design entirely.  what about simply rendering the self submitting form in the Page class as that's what the page class is for - handling the current context.

    Wednesday, March 18, 2020 1:51 PM
  • User1535942433 posted

    Hi kengkit,

    Accroding to your description,I couldn't understand your reuqirment clearly.As mgebhard says,how do you call post() method?

    Could you post full codes to us?It will help us to solve your problem.

    Best regards,

    Yijing Sun

    Thursday, March 19, 2020 7:24 AM
  • User944339287 posted

    Hi,

    This is web application.

    My complete code is at my 1st port. payment() will be triggered once the button is clicked.

    And the Public Class RemotePostPayment will be using for the post action. TQ

    Friday, March 20, 2020 5:45 AM
  • User475983607 posted

    This is web application.

    My complete code is at my 1st port. payment() will be triggered once the button is clicked.

    And the Public Class RemotePostPayment will be using for the post action. TQ

    I'm guessing you copied the Url or Class from the internet.  The URL string contains extra characters.   I modified your code slightly to make it easier to debug.  I removed the onload and added a submit button.  Clicking the submit button showed clearly an error and the encoded text in the browser's address bar.  I simply deleted the Url assignment in the Class and typed in a new line.  This removed the hidden characters copied from the internet.

    Imports System.Web
    Imports System.Collections.Specialized
    Imports System.Net
    
    Partial Public Class RemotePostPayment
        Private inputValues As NameValueCollection
    
        Public Property Url As String
            Get
                Return m_Url
            End Get
            Set(ByVal value As String)
                m_Url = value
            End Set
        End Property
    
        Private m_Url As String
    
        Public Property Method As String
            Get
                Return m_Method
            End Get
            Set(ByVal value As String)
                m_Method = value
            End Set
        End Property
        Private m_Method As String
    
        Public Property FormName As String
            Get
                Return m_FormName
            End Get
            Set(ByVal value As String)
                m_FormName = value
            End Set
        End Property
    
        Private m_FormName As String
    
        Public ReadOnly Property Params As NameValueCollection
            Get
                Return inputValues
            End Get
        End Property
    
        Public Sub New()
    
            inputValues = New NameValueCollection()
    
            Url = "https://localhost:44362/Pay/Payment"
    
            Method = "post"
            FormName = "ePayment"
    
        End Sub
    
        Public Sub Add(ByVal name As String, ByVal value As String)
            inputValues.Add(name, value)
        End Sub
        'onload=""document.{0}.submit()""
        Public Sub Post()
            Dim context = HttpContext.Current
    
            context.Response.Clear()
            context.Response.Write("<html><head>")
            context.Response.Write("</head><body>")
            context.Response.Write(String.Format("<form name=""{0}"" method=""{1}"" action=""{2}"" >", FormName, Method, Url))
            For i As Integer = 0 To inputValues.Keys.Count - 1
                context.Response.Write(String.Format("<input name=""{0}"" type=""hidden"" value=""{1}"" />", HttpUtility.HtmlEncode(inputValues.Keys(i)), HttpUtility.HtmlEncode(inputValues(inputValues.Keys(i)))))
            Next
            context.Response.Write("<input type='submit' value='submit' />")
            context.Response.Write("</form>")
            context.Response.Write("</body></html>")
            context.Response.[End]()
        End Sub
    
    End Class
    

    Friday, March 20, 2020 11:24 AM