1. Dinesh Babu Sivakumar
  2. PowerBuilder
  3. Monday, 17 September 2018 19:53 PM UTC

I'm trying to send the pdf document through RESTful API service using PowerBuilder 2017R3 (Windows 10 OS) but i could not able to add the body parameters (metadata - in the form of JSON data and content - pdf document in the form of binary object) in these httpobject.

Do we've any options in latest PB 2017 R3 to add these body parameters (not the headers) or any other alternate options?  (attaching below the screenshot from Postman tool - it was working with these body)

 

Attachments (1)
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 18 September 2018 05:32 AM UTC
  2. PowerBuilder
  3. # 1

You have to combine the two fields in the data section. Use a "boundary" (a string that must be unique in the whole data) to separate the form data from file data and specify this boundary in the header.

Here is a shortened example that I use with MSXML API (but should be the same with HTTP Client):

 

// the body part
ls_boundary = "$$$Boundary$$$"
ls_metadata = ""
lblob_file = ... // your file
lblob_data = blob ("--"  + ls_BOUNDARY + "~r~n" + &
                 'Content-Disposition: form-data; name="metadata"' + &
                 "~r~n~r~n" + ls_metadata + "~r~n", EncodingUTF8!) + &
                 blob ("--"  + ls_BOUNDARY + "~r~n" + &
                 'Content-Disposition: form-data; name="file"; filename="TEST.pdf"' + &
                 "~r~nContent-Type: application/pdf~r~n~r~n", EncodingUTF8!) + &
                 lblob_file + blob ("~r~n--"  + ls_BOUNDARY + "--~r~n", EncodingUTF8!)

// the header part
SetRequestHeader ("Content-Type", "multipart/form-data; boundary=" + ls_BOUNDARY)

 

 

Comment
  1. Dinesh Babu Sivakumar
  2. Tuesday, 18 September 2018 14:47 PM UTC
Thanks René Ullrich. Now I could able to send the document using hardcoded Authorization headers. I need to pass the user id and password using Basic authorization headers.. I was using the below hardcoded authorization headers as

httpClient.SetRequestHeader("Authorization", "Basic xxxxx==");. My question is how to convert the user id and password and include those ANSI Characters into basic authorization headers.
  1. Helpful
  1. Dinesh Babu Sivakumar
  2. Tuesday, 18 September 2018 17:00 PM UTC
I got it working by including the headers in the below code snippet:



ls_credentials = "user_id:pw"

lblb_credentials = Blob(ls_credentials, EncodingUTF8!)

ls_Base64credentials = lnv_CoderObject.Base64Encode(lblb_credentials)

SetRequestHeader("Authorization", "Basic "+ls_Base64credentials)



Thanks,

Dinesh Babu
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.