Hi,
while trying to implement multipart post I've found a possible issue but I wanted to check with the community before logging a bug.
The code I'm using is pretty standard, as found in multiple existing threads:
However, by sniffing the network traffic, I noticed that the Content-type header that is generated by B4J is missing the boundary element, thus the request fails on the server end as the file post is not recognized to be part of my multipart Post.
This B4J app would generate the following, and fail:
A working session with cURL would instead generate the following:
The "boundary=------------------------1461124740692" is not added by B4J to the multipart/form-data Content-type, while in cURL the boundary string is automatically generated.
So in order to make it work, my code needs to be changed to this:
Can someone confirm my assumption that B4J should generate a random boundary string autonomously instead of having to add the magic string "---------------------------1461124740692" in my code?
Thanks
Andrea
while trying to implement multipart post I've found a possible issue but I wanted to check with the community before logging a bug.
The code I'm using is pretty standard, as found in multiple existing threads:
B4J POST multipart not working:
Dim job As HttpJob
Dim ret As String = "ERROR"
job.Initialize("job", Me)
job.PostMultipart(URL, Null, Array(fd))
job.GetRequest.SetHeader("User-Agent", useragent)
job.GetRequest.SetContentType("multipart/form-data")
job.GetRequest.SetHeader("Authorization", auth)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
ret = job.GetString
End If
job.Release
Return ret
However, by sniffing the network traffic, I noticed that the Content-type header that is generated by B4J is missing the boundary element, thus the request fails on the server end as the file post is not recognized to be part of my multipart Post.
This B4J app would generate the following, and fail:
B4J Network dump:
Content-type: multipart/form-data
--------------------------1461124740692
Content-Disposition: form-data; name="parameters"; filename="Params.json"
Content-Type: application/json
{ ... }
A working session with cURL would instead generate the following:
cURL Network dump:
Content-type: multipart/form-data; boundary=------------------------xyz1234abcdef
--------------------------xyz1234abcdef
Content-Disposition: form-data; name="parameters"; filename="Params.json"
Content-Type: application/json
{ ... }
The "boundary=------------------------1461124740692" is not added by B4J to the multipart/form-data Content-type, while in cURL the boundary string is automatically generated.
So in order to make it work, my code needs to be changed to this:
B4J POST multipart working!:
Dim job As HttpJob
Dim ret As String = "ERROR"
job.Initialize("job", Me)
job.PostMultipart(URL, Null, Array(fd))
job.GetRequest.SetHeader("User-Agent", useragent)
job.GetRequest.SetContentType("multipart/form-data; boundary=---------------------------1461124740692")
job.GetRequest.SetHeader("Authorization", auth)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
ret = job.GetString
End If
job.Release
Return ret
Can someone confirm my assumption that B4J should generate a random boundary string autonomously instead of having to add the magic string "---------------------------1461124740692" in my code?
Thanks
Andrea