0

I'm integrating Stripe payments in an aspx site (VB, .NET 4.7.2). I took Javascripts from Stripe samples. I try to call this method of the backend:

<WebMethod()>
Public Shared Function CreateStripePaymentIntent(ByVal aPrice As String) As PaymentIntent
    ...
End Function

from a Javascript in the page: (here the parameter is a fixed value, to simplify)

fetch("PayOrder.aspx/CreateStripePaymentIntent?aPrice=111", {
  method: "POST",
  headers: {
    'Accept': 'application/json',                                   
    "Content-Type": "application/json"
    }
  body: JSON.stringify(purchase)
})

If I remove the parameter all works well (but is useless). If I try to pass the parameter I always have error 500: POST http://localhost:14987/PayOrder.aspx/CreateStripePaymentIntent?aPrice=111 Status 500 Internal Server Error Version HTTP/1.1 Transferred 0,98 kB (660 B size) Referrer Policy strict-origin-when-cross-origin

Message "No value for parameter 'aPrice'." (my translation from italian to english!)

Someone can tell me WHY this parameter does not reach the backend?

2

1 Answer 1

1

The values are sent in the request body, in the format that the content type specifies.

Usually the content type is application/x-www-form-urlencoded, so the request body uses the same format as the query string:

parameter=value&also=another

When you use a file upload in the form, you use the multipart/form-data encoding instead, which has a different format. It's more complicated, but you usually don't need to care what it looks like, so I won't show an example, but it can be good to know that it exists.

for Json content type is application/json

fetch("PayOrder.aspx/CreateStripePaymentIntent", {
  method: 'POST',
  headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
  },
  body: JSON.stringify({ aPrice: 111 })
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.