1

I would like to know how I can echo "data for param1" on the server. I have no idea how to access it.

If it were a file, I would use

echo $_FILES["file"]["name"];

But I don't know how to access "data for param1".

Thank you!

Dim msxml As msxml.XMLHTTPRequest
Dim data As String
Dim boundary As String

Set msxml = New msxml.XMLHTTPRequest

boundary = "MyCustomBoundary7MA4YWxkTrZu0gW"

msxml.Open "POST", "http://httpbin.org/post", False

msxml.setRequestHeader "Content-Type", "multipart/form-data;Charset=UTF-8; boundary=" & boundary

data = ""
data = data & "--" & boundary & vbCrLf
data = data & "Content-Disposition: form-data; name=""param1""" & vbCrLf
data = data & "Content-Type: text/plain" & vbCrLf & vbCrLf
data = data & "data for param1" & vbCrLf

data = data & "--" & boundary & vbCrLf
data = data & "Content-Disposition: form-data; name=""param2""" & vbCrLf
data = data & "Content-Type: text/plain" & vbCrLf & vbCrLf
data = data & "other data for param2" & vbCrLf

data = data & "--" & boundary & "--"

msxml.Send data
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • See [Superglobals](https://www.php.net/manual/en/language.variables.superglobals.php). Does this answer your question? [Get all variables sent with POST?](https://stackoverflow.com/questions/8207488/get-all-variables-sent-with-post) – ficuscr Feb 25 '22 at 19:48
  • Looks like you're sending a post request so use `$_POST` instead of `$_FILES`. Also see https://stackoverflow.com/a/14794856/296555 if your $_POST array is empty. – waterloomatt Feb 25 '22 at 19:51
  • 1
    I feel like there are maybe issues with your XMLHTTPRequest code? Looks like you are combining `enctype` and `Content-Type` headers (hmm that might be valid actually). Not sure though on the use of double quotes in the data. Think your request is probably not valid. Try some more debugging / error handling there? Won't see what you expect server side if not sent what you expect. Ensure where the issue is. – ficuscr Feb 25 '22 at 19:56
  • @ficuscr You where right! vbcrlf was missing. – tmighty Feb 25 '22 at 20:07
  • 1
    Seeing you probably know more about string concatenation there than I do. But, missing quote on definition of `boundary` in header? `boundary="" & boundary & """` Been a while since I coded VB ;) Need a way to get (inspect) the request and play with it - WireShark or something easier. – ficuscr Feb 25 '22 at 20:08

0 Answers0