1

I have the following CURL request which pointing to my service:

curl -X POST \
  http://go.example.com/ \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Postman-Token: cf0c1ab5-08ff-1aa2-428e-24b855e1a61c' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F fff=vvvvv \
  -F rrrr=ddddd \
  -F xx=something

I'm trying to catch the xx paramter in classic ASP code. I tried 'Request("xx")' and 'Request.Form("xx")'.

Do you have any idea?

Joel Coehoorn
  • 362,140
  • 107
  • 528
  • 764
Gil Allen
  • 1,065
  • 13
  • 22

1 Answers1

2

This is from the CURL documentation

-F, --form

(HTTP SMTP IMAP) For HTTP protocol family, this lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388.

When a form is submitted to Classic ASP using a content-type of multipart/form-data the only method available is Request.BinaryRead() as Request.Form is for application/x-www-form-urlencoded data.

Here is a quick example of calling Request.BinaryRead() to get you started:

<%
'Should be less than configured request limit in IIS.
Const maxRequestSizeLimit = ...
Dim dataSize: dataSize = Request.TotalBytes
Dim formData

If dataSize < maxRequestSizeLimit Then
  'Read bytes into a SafeArray
  formData = Request.BinaryRead(dataSize)
  'Once you have a SafeArray its up to you to process it.
  ...
Else
  Response.Status = "413 PAYLOAD TOO LARGE"
  Response.End
End If
%>

Parsing a SafeArray isn't easy

If you want to still use Request.Form you can do by specifying the form parameters in the CURL command using -d instead of -F. From the documentation;

-d, --data

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.

So the CURL command would be something like;

curl -X POST \
  http://go.mytest-service.com/ \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d fff=vvvvv \
  -d rrrr=ddddd \
  -d xx=something

You would then retrieve the xx parameter in Classic ASP using;

<%
Dim xx: xx = Request.Form("xx")
%>

Useful Links

user692942
  • 14,779
  • 6
  • 66
  • 157
  • 1
    That Request.BinaryRead seems to get me somewhere... I'll let you know how i'm doing. 10x! – Gil Allen Oct 17 '18 at 11:04
  • 1
    @GilAllen word of warning, parsing a binary SafeArray is not for the faint hearted in Classic ASP. You could avoid this by using `-d` instead of `-F` to POST data using `application/x-www-form-urlencoded` instead of `multipart/form-data` which will allow you to retrieve the values using `Request.Form`. – user692942 Oct 17 '18 at 13:29
  • Indeed, but I'n not always the sending side. Any way , it seems the sender side have changed the POST format and it works normally now. – Gil Allen Oct 18 '18 at 12:33