Home > Mobile >  How to send form-data with RestClient, if data received from a hash?
How to send form-data with RestClient, if data received from a hash?

Time:10-22

I have an API endpoint that requires data to be sent to it as form-data. I am using RestClient for sending the data. The problem is that I do not manage to give the data for the request in a way, that the endpoint would be able to read it. This is what I have tried:

RestClient::Request.execute(
    method: :post,
    url: url,
    payload: {
      multipart: true,
      data: {
         "user": "test",
         "phase": "test",
         "job_id": "test"
      }
    },
    headers: { Authorization: 'Basic '   Base64.encode64(auth_details), content_type: "multipart/form-data"}
  )

Any advices how I could add the hash-data for the request in a way that the endpoint could read it as a form?

EDIT1:

The endpoint does receive the request. The endpoint is written with Flask and it tries to read the form parameters using flask.request in the following way:

request.form.get("user")

CodePudding user response:

I managed to get the request working by changing the reuquest to be the following:

RestClient::Request.execute(
   method: :post,
   url: url,
   payload: {
      "user": "test",
      "phase": "test",
      "job_id": "test"
   },
   headers: { Authorization: 'Basic '   Base64.encode64(auth_details), 
   content_type: "multipart/form-data"}
)
  • Related