Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Fetch image/tiff with CL_HTTP_CLIENT

bjorn-henrik_zink
Contributor
0 Likes
756

Hi,

I am trying to fetch an image using the CL_HTTP_CLIENT class. My coding looks something like this:


  TRY.
      " Create the HTTP client
      CALL METHOD cl_http_client=>create_by_url
        EXPORTING
          url                = lv_img_url
        IMPORTING
          client             = lo_client
        EXCEPTIONS
          argument_not_found = 1
          plugin_not_active  = 2
          internal_error     = 3.

      IF sy-subrc = 0.
        " Set header fields.
        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = '~request_method'
            value = 'POST'.

        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = '~server_protocol'
            value = 'HTTP/1.1'.

        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = 'Content-Type'
            value = 'image/tiff'.

        "send and receive
        lo_client->send( ).
        lo_client->receive( ).

        "get status
        lo_client->response->get_status( IMPORTING code = lv_return_code ).

        "get the response as binary data
        lv_img_xstring = lo_client->response->get_data( ).

        "close connection
        lo_client->close( ).
      ENDIF. "sy-subrc = 0
    CATCH cx_root.
  ENDTRY.

The code is working fine when the url is pointing to a .jpeg file (and removing the set_header_field part). However, with an .tiff image url it does not work. Any help is greatly appreciated.

Thanks.

Hi,

I am trying to fetch an image using the CL_HTTP_CLIENT class. My coding looks something like this:


  TRY.
      " Create the HTTP client
      CALL METHOD cl_http_client=>create_by_url
        EXPORTING
          url                = lv_img_url
        IMPORTING
          client             = lo_client
        EXCEPTIONS
          argument_not_found = 1
          plugin_not_active  = 2
          internal_error     = 3.

      IF sy-subrc = 0.
        " Set header fields.
        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = '~request_method'
            value = 'POST'.

        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = '~server_protocol'
            value = 'HTTP/1.1'.

        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = 'Content-Type'
            value = 'image/tiff'.

        "send and receive
        lo_client->send( ).
        lo_client->receive( ).

        "get status
        lo_client->response->get_status( IMPORTING code = lv_return_code ).

        "get the response as binary data
        lv_img_xstring = lo_client->response->get_data( ).

        "close connection
        lo_client->close( ).
      ENDIF. "sy-subrc = 0
    CATCH cx_root.
  ENDTRY.

The code is working fine when the url is pointing to a .jpeg file (and removing the set_header_field part). However, with an .tiff image url it does not work. Any help is greatly appreciated.

Thanks.

1 REPLY 1
Read only

bjorn-henrik_zink
Contributor
0 Likes
561

Moving the question to the Web Dynpro ABAP forum since I am using the code in a Web Dynpro ABAP application.