URLConnection form data

Has anyone successfully been able to post form-data message with URLConnection ?

x-www-urlencoded does not work for attachments, which is where form-data comes in.

I have been trying to manually make the form-data package but I am guessing Xojo is doing something when I call SetRequestContent that messes it maybe.

Format of the message in PostMan for Form data is as follows:

POST /filecontroller/api/sendfile HTTP/1.1
Host: localhost:5000
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=‚ÄúComponent‚ÄĚ

PictureEffects
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=‚ÄúPath‚ÄĚ

Xojo x64
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=‚ÄúFile‚ÄĚ; filename="/C:/Users/Bj√∂rn Eir√≠ksson/Pictures/test.png"
Content-Type: image/png

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW

I wrote some code to do this a few years ago for the old HTTPSocket. Should be portable to URLConnection:

https://www.boredomsoft.org/file-uploads-form-encodings-and-xojo.bs

1 Like

Thanks I will take a look

I was able to fix the code I was working on for it, it was the CRLF I only had LF, the Hex editor I was using to examine the post does not show t he CR !

Thanks !