0

How can I use MSXML2.serverXMLHTTP.6.0 post data to server with classic asp like the picture as below.

enter image description here my code:

Dim oHttp                    
Dim strResult
Set oHttp = CreateObject("MSXML2.serverXMLHTTP.6.0")
oHttp.setOption(2) = 13056
oHttp.open "POST", url, false
oHttp.setRequestHeader "SecretKey", skey
oHttp.setRequestHeader "AGENCY_ID", aid
oHttp.setRequestHeader "Content-Type", "application/json"
oHttp.send jsondata
oStr=oHttp.responseText
response.write oStr


curl --location --request POST 'https://nh.ccc.com' \
--header 'AGENCY_ID: 00000006' \
--header 'SecretKey: EEEEEEEEEEEEEEEEEEEEEEEE' \
--form 'AGENCY_ID=00000006' \
--form 'SecretKey=EEEEEEEEEEEEEEEEEEEEEEEE' \
--form 'jsonfile=@/C:/Users/kqqq/Downloads/file20210888888.json'
Kevin Kao
  • 9
  • 4
  • You are passing the values as HTTP headers but according to the Postman screenshot, you should be passing them in the POST body as `x-www-form-urlencoded` content. See [this example](https://stackoverflow.com/a/37462944/692942). I'm not entirely sure why you have `jsondata` when it's expecting a standard form post body. – user692942 Sep 03 '21 at 12:38
  • 1
    Thank you all reply. I need to upload a file not string via asp and not js,pure asp – Kevin Kao Sep 03 '21 at 13:12
  • Hi user692942 It's not the answer for my problem – Kevin Kao Sep 03 '21 at 13:16
  • @KevinKao Does that even work in CURL? That answer explains how to make a form post via an XHR (which is equivalent to firing a request via Postman or CURL). So actually I disagree, if that doesn't help with your problem I'm sorry you're just doing it wrong. Show us a working CURL request and response for what you want to achieve via Classic ASP then we'll talk. – user692942 Sep 03 '21 at 13:58
  • It's important to note, if you are trying to upload a file then you have to use `multipart/form-data` (which means the Postman image above is wrong as it's set to `x-www-form-urlencoded`). Also, Classic ASP support for `multipart/form-data` is non existent and everything has to be coded manually to read the binary stream (`Request.BinaryRead()`) yourself. See [application/x-www-form-urlencoded or multipart/form-data?](https://stackoverflow.com/q/4007969) – user692942 Sep 03 '21 at 16:18

0 Answers0