Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Sending File over Form Data #43

Open
mskhaled opened this issue Mar 29, 2024 · 1 comment
Open

Issue with Sending File over Form Data #43

mskhaled opened this issue Mar 29, 2024 · 1 comment

Comments

@mskhaled
Copy link

I'm encountering an issue while attempting to send a file over form data in VB6 using cHTTPRequest. I'm trying to replicate a cURL request that uploads a document to an API endpoint. The cURL command works as expected, but I'm having trouble achieving the same functionality

curl --location --request POST "https://api.mindee.net/v1/products/mindee/invoices/v4/predict" \
--header 'Authorization: Token fd1e97c821b43579a93b571d95aec10d' \
--form 'document=@"/D:/Bon de Livraison.pdf"'
Dim urlText As String
urlText = "https://api.mindee.net/v1/products/mindee/invoices/v4/predict"

With myRequest
    .SetRequestHeader "Authorization", "Token <API TOKEN>"
    .SetRequestHeader "Content-Type", "multipart/form-data"
    .Open "POST", urlText, False
    .Send "document=@" & Chr(34) & "/D:/Bon de Livraison.pdf" & Chr(34)
End With

I would appreciate any insights or suggestions on how to correctly send a file over form data in VB6 using cHTTPRequest. Thank you for your assistance!

@wqweto
Copy link
Owner

wqweto commented Mar 29, 2024

I would appreciate any insights or suggestions on how to correctly send a file over form data in VB6 using cHTTPRequest.

It's the same way when using WinHttpRequest. You have to prepare request body you pass to Send method to include your binary file as part of multipart/form-data form values as specified in RFC 7578.

Currently you are emulating curl parameters but this is not how POST web requests work because curl translates its parameters to RFC compliant web requests while with WinHttpRequest/cHttpRequest you have to do this manually (i.e. load the binary file, format request boundaries, etc.)

Here is a sample in VB6 how to prepare request body in multipart/form-data format: Using WinInet to post binary file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants