Classic ASP: requesting variables from 'Content-Disposition: form-data'

74 Views Asked by At

I am integrating Paypal's Checkout API into a legacy Classic ASP site.

When sending via this front end js:

        var postData = {paypal_order_check: 1, order_id: orderData.id};
        fetch('paypal_checkout_validate.asp', {
            method: 'POST',
            headers: {'Accept': 'application/json'},
            body: encodeFormData(postData)
        })

This is the payload that is being sent:

------WebKitFormBoundaryZrUIbyscgWBpTxX
Content-Disposition: form-data; name="paypal_order_check"

1
------WebKitFormBoundaryZrUIbyscgWBpTxX
Content-Disposition: form-data; name="order_id"

3JV215PS364212N
------WebKitFormBoundaryZrUIbyscgWBpTxX--

I am trying to 'request' these 2 variables paypal_order_check and order_id but cant figure out who do to that. A generic request or request.form does not work, but using this code (via https://github.com/rcdmk/aspJSON JSON class):

Set UTF8Enc = CreateObject("System.Text.UTF8Encoding") // .NET COMPONENT, required on the server app pool
Set JSON = new JSONobject

lngBytesCount = Request.TotalBytes
request_body = UTF8Enc.GetString(Request.BinaryRead(lngBytesCount))

Set request_json = JSON.parse(request_body)
   
Set JSON = nothing  

--> then I do get the entire payload into the request_json variable. But what next? I thought i could do paypal_order_check = request("paypal_order_check") - bit that is empty too.

Thanks

1

There are 1 best solutions below

0
Preston PHX On

If the backend is expecting JSON, don't use encodeFormData(). That makes no sense.

Use JSON.stringify()