Is it possible to call an URL passing website parameters?

Viewed 970

I am writing code for a custom SAP program regarding some Vendor information. In my program flow, there is a possibility of me trying to use a Vendor VAT Number that belongs to an unknown Vendor. There is a Web site (EU Based - https://ec.europa.eu/taxation_customs/vies/) for such purposes that requires a country key and the specified VAT Number in order for it to provide an answer with the available Company information (only works for company VAT numbers of course). My problem is that I cannot seem to find any way to pass those parameters dynamically to the Web site without needing the user to interfere during this process. Manually, the process would be to select a country key, type in a VAT number and press 'Verify'.

Is there any way for me to call this specific Web site URL and "bypass" this process to only display the result page? For now, I'm using the following Function Module to just call the specified URL, in lack of any better choices.

call function 'CALL_INTERNET_ADRESS'
          exporting
            pi_adress           = 'https://ec.europa.eu/taxation_customs/vies/'
          exceptions
            no_input_data       = 1
            others              = 2.
2 Answers

You can use CL_HTTP_CLIENT class or HTTP_POST/HTPP_GET FM.

You need to install given web page SSL root certificate to your system with STRUST t-code.

Example usage of CL_HTTP_CLIENT below.

DATA: lv_url     TYPE string  VALUE 'http://mkysoft.com/ip.php'.
DATA: o_client   TYPE REF TO if_http_client.
DATA: lv_http_rc TYPE i.
DATA: lv_reason  TYPE string.
DATA: lt_fields  TYPE tihttpnvp.

TRY.
    cl_http_client=>create_by_url( EXPORTING
                                      url    = lv_url
                                   IMPORTING
                                      client = o_client
                                   EXCEPTIONS
                                      OTHERS = 0 ).

    o_client->request->get_header_fields( CHANGING fields = lt_fields ).
    o_client->request->set_header_field( name = '~request_uri' value = '/ip.php' ).
    o_client->request->set_header_field( name = '~host' value = 'mkysoft.com' ).
    o_client->request->set_method( if_http_request=>co_request_method_get ).
    o_client->send( ).
    o_client->receive( ).
    o_client->response->get_status( IMPORTING
                                      code   = lv_http_rc
                                      reason = lv_reason ).
* Error check
    IF lv_http_rc = 200.
      DATA(lv_xml) = o_client->response->get_cdata( ).
*     Handle error
    ELSE.
      WRITE: / 'Fehler: ', lv_http_rc.
    ENDIF.
    o_client->close( ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

EU Commission has a SOAP service for vat numbers. See the info page https://ec.europa.eu/taxation_customs/vies/technicalInformation.html

and that it even supports http http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl

You have a non screen scrape method, proper interface you should look at.

On the other point of Avoiding SSL. Make a basic guide for customers to add the European commission cert to their SAP system. If someone is complaining about that, then they are a serious user of the internet. Every sap on premise user, that needs to call the internet adds certs. Http is dead....

Related