Bug in request function when working with multipart/form-data
I found a bug with the request function when working with multipart/form-data. The second and following pairs of form variables require an extra space at the beginning!
Here is the problem: GitHub Issue #28
Thanks, Ali
Thanks, Ali. Do you know why is the extra space needed for the 2nd and following form pairs? I suppose the change is needed here:
https://github.com/fortran-lang/http-client/blob/d65b4b1eb96ec9a4ddbb98252335aa37ad24ace0/src/http/http_client.f90#L250-L262
I wonder if this has to do with how curl_easy_escape works.
Thank you for your prompt response.
My test shows that the function prepare_form_encoded_str isn't being called. I think this function should be called within the client_get_response function.
Hello Ali, as you are utilizing both the file and form concurrently, this code is currently operational. I will proceed to test this code: https://github.com/fortran-lang/http-client/blob/d65b4b1eb96ec9a4ddbb98252335aa37ad24ace0/src/http/http_client.f90#L440-L459
Thank you for your response.
This solution may not be ideal, but it works:
! if both file and form are passed
if(allocated(request%form)) then
part_ptr = curl_mime_addpart(mime_ptr)
status = curl_mime_data(part_ptr, request%form(1)%value, CURL_ZERO_TERMINATED)
status = curl_mime_name(part_ptr, request%form(1)%name)
if (size(request%form) > 1) then
do i=2,size(request%form)
part_ptr = curl_mime_addpart(mime_ptr)
status = curl_mime_data(part_ptr, request%form(i)%value, CURL_ZERO_TERMINATED)
status = curl_mime_name(part_ptr, " "//request%form(i)%name)
end do
end if
end if