Skip to main content

We need a multipart/form-data request to receive a raw-body message.

We dont understand this DUMP_FILES_CONTENTS method realy.

hv_UHTTP->SET_FLAGS(3)
hv_UHTTP->DUMP_FILE_CONTENTS(sv_LOCAL_FILE_NAME, "")
hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
hv_UHTTP->DUMP_FILE_CONTENTS("","")

The SEND-Methode throws an -10 for the URL we get, but we dont want to use the url!
We only need the raw-body!
What is the right way to do this?
Thanks a lot


We need a multipart/form-data request to receive a raw-body message.

We dont understand this DUMP_FILES_CONTENTS method realy.

hv_UHTTP->SET_FLAGS(3)
hv_UHTTP->DUMP_FILE_CONTENTS(sv_LOCAL_FILE_NAME, "")
hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
hv_UHTTP->DUMP_FILE_CONTENTS("","")

The SEND-Methode throws an -10 for the URL we get, but we dont want to use the url!
We only need the raw-body!
What is the right way to do this?
Thanks a lot


Hello Dirk,


can you please post a full code example?

What are you trying to do?

How does the answer of the webservice should look like?


hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
Content is an inout parameter, where you put "" in place.

Regards
Norbert

Hello Dirk,


can you please post a full code example?

What are you trying to do?

How does the answer of the webservice should look like?


hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
Content is an inout parameter, where you put "" in place.

Regards
Norbert

Hi Norbert,

into the Uniface Help there is this comment for using the content into the DUM_FILE_CONTENS method:

It cannot be specified when using the file operations such as LOAD_FILE_CONTENTS and DUMP_FILE_CONTENTS.

And the sample for this method dont use the content also!?


We need a multipart/form-data request to receive a raw-body message.

We dont understand this DUMP_FILES_CONTENTS method realy.

hv_UHTTP->SET_FLAGS(3)
hv_UHTTP->DUMP_FILE_CONTENTS(sv_LOCAL_FILE_NAME, "")
hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
hv_UHTTP->DUMP_FILE_CONTENTS("","")

The SEND-Methode throws an -10 for the URL we get, but we dont want to use the url!
We only need the raw-body!
What is the right way to do this?
Thanks a lot


Hello Dirk,


maybe there is something wrong with your url!?

Have you testet the url with the browser?


Here is an example that should work:


trigger detail
	variables
		handle vUHTTP
		numeric vStatus
		string vURI, vHeaders, vContent, vResponse 
	endvariables
	newinstance "UHTTP", vUHTTP
	vURI = "https://www.titania-foto.com/wp-content/uploads/2019/03/bunte-tulpen-1.jpg"
	vUHTTP->SET_FLAGS(3)
	vUHTTP->DUMP_FILE_CONTENTS("C:\\TEMP\\Tulpe.jpg", "")
	vStatus = vUHTTP->SEND(vURI, "GET", "", "", vHeaders, "", vResponse)
	vUHTTP->DUMP_FILE_CONTENTS("", "")
	vUHTTP = 0
end


Norbert


We need a multipart/form-data request to receive a raw-body message.

We dont understand this DUMP_FILES_CONTENTS method realy.

hv_UHTTP->SET_FLAGS(3)
hv_UHTTP->DUMP_FILE_CONTENTS(sv_LOCAL_FILE_NAME, "")
hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
hv_UHTTP->DUMP_FILE_CONTENTS("","")

The SEND-Methode throws an -10 for the URL we get, but we dont want to use the url!
We only need the raw-body!
What is the right way to do this?
Thanks a lot


Hi Dirk

I wrote this procedure to dump the content into a file.
Maybe you can find a hint for your problem challenge 🙂

Ingo




ENTRY LP_AAK_REST_DUMP
  params
    string  v_URL_PART2 :IN
    string  v_HEADER    :INOUT
    struct  vy_CONTENT  :INOUT
    string  v_FILENAME  :IN
  endparams
  variables
    string  v_METHOD
    string  v_HEADER_IN
    numeric v_STS_SND
    numeric v_STS_RSP
    numeric v_LENGTH
    string  v_TYPE_OUT
    numeric v_TRIES
    string  v_PEC
    numeric v_STATUS
  endvariables

  v_METHOD = "GET"
  v_HEADER_IN = v_HEADER

  v_TRIES=0

 TAG_NOCHMAL:
  v_TRIES+=1
  putmess "-------------------Try %%v_TRIES%%% --------------------------"
  IF(0)
    $ioprint=4095
    $proc_tracing=4095
    $traceprint=4095
  ENDIF
  IF($APP_HND_UHTTP$=="")
    newinstance "UHTTP", $APP_HND_UHTTP$
    $APP_HND_UHTTP$->"SET_FLAGS"(8)  ; Send headers with all methods. By default, headers are sent only on the POST and PUT methods.
  ENDIF

  putmess "DUMP_FILE_CONTENTS('%%v_FILENAME%%%', 'TCPRCVBUF=1m')"
  $APP_HND_UHTTP$->"DUMP_FILE_CONTENTS"(v_FILENAME, "TCPRCVBUF=1m")
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% before dump to file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
  ENDIF


  v_HEADER = v_HEADER_IN

  IF($APP_TOKEN$!="")
    putitem/id/case v_HEADER, "access_token",$APP_TOKEN$
  ENDIF

  IF(0)
    call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%")
  ENDIF


  putmess ">SEND(%%$APP_URL_BASE$%%v_URL_PART2%%%','GET','%%v_HEADER%%%')"
  $APP_HND_UHTTP$->"SEND"("%%$APP_URL_BASE$%%v_URL_PART2%%%","GET", "", "",v_HEADER, "", v_STS_RSP)
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ENDIF
  v_STS_SND = $status
  putmess ""READ_CONTENT"($99)
    IF($status<0) BREAK
    v_STS_SND = $status
    IF(v_STS_SND>400) BREAK
  ENDWHILE


  IF(1)
    call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%  : STS=%%v_STS_SND%%%/%%v_STS_RSP%%%")
  ENDIF

  IF(v_STS_SND<0)
    call LP_ERR("UHTTP error %%v_STS_SND%%% '%%v_URL_PART2%%%'")
    v_STATUS=v_STS_SND
    GOTO TAG_ENDE
  ENDIF

  IF(v_STS_SND==403) ; 28.11.2018,IST
    RETURN(-9999)
  ENDIF

  IF(v_STS_SND>=400 || v_STS_RSP>=400)
    call LP_DBG_REST_ERR1(v_METHOD,v_URL_PART2,v_STS_SND,v_HEADER_IN,"",v_STS_RSP,"","")
    v_STATUS=$status
    GOTO TAG_ENDE
  ENDIF

  v_TYPE_OUT = $item("Content-Type",v_HEADER)

  putmess "GET_INFO('LENGTH', '')"
  $APP_HND_UHTTP$->"GET_INFO"("LENGTH","")
  v_LENGTH = $status

  putmess "DUMP_FILE_CONTENTS('', '')"
  $APP_HND_UHTTP$->"DUMP_FILE_CONTENTS"("", "")
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% when dump to file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
  ENDIF

  IF(1)
    call LP_MELD("Dumped %%v_LENGTH%%% bytes to '%%v_FILENAME%%%'")
  ENDIF
  $99 = $lfileproperties(v_FILENAME)
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% after dump of file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
    IF(1) call LP_MELD($99)
  ENDIF
  IF(1)
    message/hint "Datei '%%v_FILENAME%%%' mit %%v_LENGTH%%% Zeichen runtergeladen"
  ENDIF
  v_STATUS=v_LENGTH

 TAG_ENDE:
  IF(0)
    $ioprint=0
    $proc_tracing=0
    $traceprint=0
  ENDIF

  IF(v_STATUS<0 & v_TRIES<10)
    sleep 100
    GOTO TAG_NOCHMAL
  ENDIF
  RETURN(v_STATUS)
END ; LP_APP_REST_DUMP
]] >

Hi Dirk

I wrote this procedure to dump the content into a file.
Maybe you can find a hint for your problem challenge 🙂

Ingo




ENTRY LP_AAK_REST_DUMP
  params
    string  v_URL_PART2 :IN
    string  v_HEADER    :INOUT
    struct  vy_CONTENT  :INOUT
    string  v_FILENAME  :IN
  endparams
  variables
    string  v_METHOD
    string  v_HEADER_IN
    numeric v_STS_SND
    numeric v_STS_RSP
    numeric v_LENGTH
    string  v_TYPE_OUT
    numeric v_TRIES
    string  v_PEC
    numeric v_STATUS
  endvariables

  v_METHOD = "GET"
  v_HEADER_IN = v_HEADER

  v_TRIES=0

 TAG_NOCHMAL:
  v_TRIES+=1
  putmess "-------------------Try %%v_TRIES%%% --------------------------"
  IF(0)
    $ioprint=4095
    $proc_tracing=4095
    $traceprint=4095
  ENDIF
  IF($APP_HND_UHTTP$=="")
    newinstance "UHTTP", $APP_HND_UHTTP$
    $APP_HND_UHTTP$->"SET_FLAGS"(8)  ; Send headers with all methods. By default, headers are sent only on the POST and PUT methods.
  ENDIF

  putmess "DUMP_FILE_CONTENTS('%%v_FILENAME%%%', 'TCPRCVBUF=1m')"
  $APP_HND_UHTTP$->"DUMP_FILE_CONTENTS"(v_FILENAME, "TCPRCVBUF=1m")
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% before dump to file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
  ENDIF


  v_HEADER = v_HEADER_IN

  IF($APP_TOKEN$!="")
    putitem/id/case v_HEADER, "access_token",$APP_TOKEN$
  ENDIF

  IF(0)
    call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%")
  ENDIF


  putmess ">SEND(%%$APP_URL_BASE$%%v_URL_PART2%%%','GET','%%v_HEADER%%%')"
  $APP_HND_UHTTP$->"SEND"("%%$APP_URL_BASE$%%v_URL_PART2%%%","GET", "", "",v_HEADER, "", v_STS_RSP)
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ENDIF
  v_STS_SND = $status
  putmess ""READ_CONTENT"($99)
    IF($status<0) BREAK
    v_STS_SND = $status
    IF(v_STS_SND>400) BREAK
  ENDWHILE


  IF(1)
    call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%  : STS=%%v_STS_SND%%%/%%v_STS_RSP%%%")
  ENDIF

  IF(v_STS_SND<0)
    call LP_ERR("UHTTP error %%v_STS_SND%%% '%%v_URL_PART2%%%'")
    v_STATUS=v_STS_SND
    GOTO TAG_ENDE
  ENDIF

  IF(v_STS_SND==403) ; 28.11.2018,IST
    RETURN(-9999)
  ENDIF

  IF(v_STS_SND>=400 || v_STS_RSP>=400)
    call LP_DBG_REST_ERR1(v_METHOD,v_URL_PART2,v_STS_SND,v_HEADER_IN,"",v_STS_RSP,"","")
    v_STATUS=$status
    GOTO TAG_ENDE
  ENDIF

  v_TYPE_OUT = $item("Content-Type",v_HEADER)

  putmess "GET_INFO('LENGTH', '')"
  $APP_HND_UHTTP$->"GET_INFO"("LENGTH","")
  v_LENGTH = $status

  putmess "DUMP_FILE_CONTENTS('', '')"
  $APP_HND_UHTTP$->"DUMP_FILE_CONTENTS"("", "")
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% when dump to file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
  ENDIF

  IF(1)
    call LP_MELD("Dumped %%v_LENGTH%%% bytes to '%%v_FILENAME%%%'")
  ENDIF
  $99 = $lfileproperties(v_FILENAME)
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% after dump of file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
    IF(1) call LP_MELD($99)
  ENDIF
  IF(1)
    message/hint "Datei '%%v_FILENAME%%%' mit %%v_LENGTH%%% Zeichen runtergeladen"
  ENDIF
  v_STATUS=v_LENGTH

 TAG_ENDE:
  IF(0)
    $ioprint=0
    $proc_tracing=0
    $traceprint=0
  ENDIF

  IF(v_STATUS<0 & v_TRIES<10)
    sleep 100
    GOTO TAG_NOCHMAL
  ENDIF
  RETURN(v_STATUS)
END ; LP_APP_REST_DUMP
]] >

Hi Info,

thank you for your code. i do ist the same way, but i think i dont understand the role SEND in this case.
My example:
I send a file like this:

newinstance "UHTTP",hv_UHTTP
hv_UHTTP->LOAD_FILE_CONTENTS("c:\\temp\\20090914_10214654.pdf", "")
hv_UHTTP->GET_INFO("length", sv_INFO)
sv_LENGTH = $status

sv_URL_UPLOAD = "%%URL_UPLOAD.DUMMY%%%?%%QUERY_PARAMS_SEND.DUMMY%%%"

putitem/id/case HEADER_UPLOAD.DUMMY, "Content-Length", "%%sv_LENGTH"

sv_HEADER_UPLOAD = HEADER_UPLOAD.DUMMY

hv_UHTTP->SEND(sv_URL_UPLOAD,METHOD_UPLOAD.DUMMY,"","",sv_HEADER_UPLOAD,sv_RESPONCE,sv_RESPONCE_STATUS)

The answere from our restapi is this:
Upload fehlgeschlagen Status -13 | Request is invalid)!
This is the code:

hv_UHTTP->SET_FLAGS(8)

hv_UHTTP->DUMP_FILE_CONTENTS(sv_LOCAL_FILE_NAME, "")
hv_UHTTP->SEND(sv_URL,"GET","","",sv_HEADERS,"",sv_RESPONSE)
hv_UHTTP->DUMP_FILE_CONTENTS("", "")

Why? WHat is the URL for send in my example?

THX

DIrk


Hi Dirk

I wrote this procedure to dump the content into a file.
Maybe you can find a hint for your problem challenge 🙂

Ingo




ENTRY LP_AAK_REST_DUMP
  params
    string  v_URL_PART2 :IN
    string  v_HEADER    :INOUT
    struct  vy_CONTENT  :INOUT
    string  v_FILENAME  :IN
  endparams
  variables
    string  v_METHOD
    string  v_HEADER_IN
    numeric v_STS_SND
    numeric v_STS_RSP
    numeric v_LENGTH
    string  v_TYPE_OUT
    numeric v_TRIES
    string  v_PEC
    numeric v_STATUS
  endvariables

  v_METHOD = "GET"
  v_HEADER_IN = v_HEADER

  v_TRIES=0

 TAG_NOCHMAL:
  v_TRIES+=1
  putmess "-------------------Try %%v_TRIES%%% --------------------------"
  IF(0)
    $ioprint=4095
    $proc_tracing=4095
    $traceprint=4095
  ENDIF
  IF($APP_HND_UHTTP$=="")
    newinstance "UHTTP", $APP_HND_UHTTP$
    $APP_HND_UHTTP$->"SET_FLAGS"(8)  ; Send headers with all methods. By default, headers are sent only on the POST and PUT methods.
  ENDIF

  putmess "DUMP_FILE_CONTENTS('%%v_FILENAME%%%', 'TCPRCVBUF=1m')"
  $APP_HND_UHTTP$->"DUMP_FILE_CONTENTS"(v_FILENAME, "TCPRCVBUF=1m")
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% before dump to file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
  ENDIF


  v_HEADER = v_HEADER_IN

  IF($APP_TOKEN$!="")
    putitem/id/case v_HEADER, "access_token",$APP_TOKEN$
  ENDIF

  IF(0)
    call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%")
  ENDIF


  putmess ">SEND(%%$APP_URL_BASE$%%v_URL_PART2%%%','GET','%%v_HEADER%%%')"
  $APP_HND_UHTTP$->"SEND"("%%$APP_URL_BASE$%%v_URL_PART2%%%","GET", "", "",v_HEADER, "", v_STS_RSP)
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ENDIF
  v_STS_SND = $status
  putmess ""READ_CONTENT"($99)
    IF($status<0) BREAK
    v_STS_SND = $status
    IF(v_STS_SND>400) BREAK
  ENDWHILE


  IF(1)
    call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%  : STS=%%v_STS_SND%%%/%%v_STS_RSP%%%")
  ENDIF

  IF(v_STS_SND<0)
    call LP_ERR("UHTTP error %%v_STS_SND%%% '%%v_URL_PART2%%%'")
    v_STATUS=v_STS_SND
    GOTO TAG_ENDE
  ENDIF

  IF(v_STS_SND==403) ; 28.11.2018,IST
    RETURN(-9999)
  ENDIF

  IF(v_STS_SND>=400 || v_STS_RSP>=400)
    call LP_DBG_REST_ERR1(v_METHOD,v_URL_PART2,v_STS_SND,v_HEADER_IN,"",v_STS_RSP,"","")
    v_STATUS=$status
    GOTO TAG_ENDE
  ENDIF

  v_TYPE_OUT = $item("Content-Type",v_HEADER)

  putmess "GET_INFO('LENGTH', '')"
  $APP_HND_UHTTP$->"GET_INFO"("LENGTH","")
  v_LENGTH = $status

  putmess "DUMP_FILE_CONTENTS('', '')"
  $APP_HND_UHTTP$->"DUMP_FILE_CONTENTS"("", "")
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% when dump to file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
  ENDIF

  IF(1)
    call LP_MELD("Dumped %%v_LENGTH%%% bytes to '%%v_FILENAME%%%'")
  ENDIF
  $99 = $lfileproperties(v_FILENAME)
  IF($procerror<0)
    v_STATUS  = $procerror
    v_PEC = $procerrorcontext
    call LP_ERR(v_PEC)
    GOTO TAG_ENDE
  ELSEIF($status<0)
    v_STATUS = $status
    v_PEC=""
    call LP_ERR("Error %%v_STATUS%%% after dump of file '%%v_FILENAME%%%'")
    GOTO TAG_ENDE
  ELSE
    IF(1) call LP_MELD($99)
  ENDIF
  IF(1)
    message/hint "Datei '%%v_FILENAME%%%' mit %%v_LENGTH%%% Zeichen runtergeladen"
  ENDIF
  v_STATUS=v_LENGTH

 TAG_ENDE:
  IF(0)
    $ioprint=0
    $proc_tracing=0
    $traceprint=0
  ENDIF

  IF(v_STATUS<0 & v_TRIES<10)
    sleep 100
    GOTO TAG_NOCHMAL
  ENDIF
  RETURN(v_STATUS)
END ; LP_APP_REST_DUMP
]] >

Hmmmm... after thinking ... iredirect the url to the restapi request url, and it works! AHA