long ll_FileNum
blob blb_file_source,blb_boundary,blb_terminus,blb_multipart,blb_file_bg
integer li_rc,li_ResponseStatusCode
HTTPClient lnv_HttpClient
string ls_endpoint , ls_file, ls_ResponseBody,ls_ResponseStatusMessage
li_ResponseStatusCode = 0
ls_ResponseBody = ''
ls_ResponseStatusMessage = ''
// Hard code the file name and endpoint for testing
ls_file = 'D:\pics\vesko.jpg'
ls_endpoint = 'http://localhost:34020/api/processor'
// Create a boundary marker for the multipart blob
string ls_Boundary = "$$$Boundary$$$"
// Read the file into a blob
blb_file_source = filetoblob(ls_file)
// Create component blobs
blb_boundary = blob('~r~n--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_file_source = blob( 'Content-Disposition: form-data; name="Source"; filename="vesko.jpg"~r~n' + "Content-Type: image/jpg~r~n~r~n", EncodingUTF8!) + blb_file_source
ls_file = 'D:\pics\dot.png'
blb_file_bg = filetoblob(ls_file)
blb_file_bg = blob( 'Content-Disposition: form-data; name="Background"; filename="dot.png"~r~n' + "Content-Type: image/pgn~r~n~r~n", EncodingUTF8!) + blb_file_bg
blb_terminus = blob('~r~n--' + ls_Boundary + '--~r~n', EncodingUTF8!)
// Concatenate blobs into a single multipart blob
blb_multipart = blb_boundary + blb_file_source+ blb_boundary+blb_file_bg+ blb_terminus
// Send the request
lnv_HttpClient = create HTTPClient
lnv_httpClient.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + ls_BOUNDARY)
lnv_httpClient.SetRequestHeader("Accept-Encoding","gzip, deflate, br")
lnv_httpClient.SetRequestHeader("Connection","keep-alive")
lnv_httpClient.SetRequestHeader("IE-INTERFACE_VERSION","1.11")
lnv_httpClient.SetRequestHeader("IE-SERVER_TYPE","BGExtractor")
lnv_httpClient.SetRequestHeader("IE-JOB_ID","111")
lnv_httpClient.SetRequestHeader("IE-RESULT_TYPE","JPG")
lnv_httpClient.SetRequestHeader("IE-PROCESSOR","Main")
li_rc = lnv_httpClient.SendRequest('POST', ls_endpoint, blb_multipart)
// obtain the response data
if li_rc = 1 then
li_ResponseStatusCode = lnv_HttpClient.GetResponseStatusCode()
ls_ResponseStatusMessage = lnv_HttpClient.GetResponseStatusText()
lnv_HttpClient.GetResponseBody(ls_ResponseBody, EncodingUTF8!)
if li_ResponseStatusCode = 200 then
MessageBox('Upload Successfull', ls_ResponseBody)
else
MessageBox('Upload Failed', ls_ResponseBody)
end if
else
MessageBox('HTTP Error', 'Error calling ' + ls_endpoint + '. Return Code ' + string(li_rc))
end if
Rest service give me error 406 - not acceptable ?! What is wrong ?!