HTTP Kommunikation

Getting started ... Alles für einen gelungenen Start.
4 Beiträge • Seite 1 von 1
4 Beiträge Seite 1 von 1

HTTP Kommunikation

Beitrag von macjam (ForumUser / 8 / 0 / 0 ) »
Guten Tag

Erstmal:
Ich bin neu hier, also Hallo. Ich entschuldige mich fals ich das falsche Forum erwischt habe aber ich fühle mich selbst definitiv noch als abap Anfänger.

Nun zu meinem Problem:
Ich muss eine Verbindung auf ein Gerät (Kardex) herstellen die Kommunikation läuft über Ethernet und das Gerät erhält die Aufrufe über eine URL die auf dem Webserver des Gerätes verarbeitet wird. Zurück kommt die Antwort in HTTP.

BSP:
Anfrage:
http://machine/cgi-bin/OrderValues.exe? ... +TAG1+TAG2...
Antwort des Gerätes:
HTTP/1.0 200 OK [0x0A]
Content-Type: text/plain [0x0A]
Contnent-Lenght: 5 [0x0A]
[0x0A]
Done. [0x0A]

Nun ich bin nicht sicher mit was ich diesen Aufruf am besten mache. Ich habe schon URLs aufgerufen mit hilfe des RFC und den Klassen/Methoden des soapincl.
Ich bin mir aber unsicher ob dieser Ansatz in Vollendung gutgenug ist.
Ich habe weiter gelesen und da ist mir dieses Http plain text zeug aufgefallen.
Villeicht könntet ihr mir ein paar Denkanstösse oder Ideen geben.

Mit freundlichen Grüssen
Macjam

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Re: HTTP Kommunikation

Beitrag von macjam (ForumUser / 8 / 0 / 0 ) »
Noch eine Frage ist es möglich ohne java stack eine http komunikation zu wirklich zu benutzen, das heisst sowohl Aufruf alsauch Antwort.
Jetzt schon mal Danke.

Re: HTTP Kommunikation

Beitrag von mcdelta0six (ForumUser / 8 / 0 / 2 ) »
Hallo,

schau dir dieses Programm mal an. Damit wird ein Aufruf an BFF gemacht, um die Umsatzsteuer Identnummer zu verifizieren.

Sollte mit jedem HTTP-Server funktionieren.

Code: Alles auswählen.


REPORT  z_httptest.


DATA: client TYPE REF TO if_http_client.
data: data type xstring.
data: dummy type string.
data: subrc type sy-subrc.
data: errortext TYPE string.
DATA: timeout type i.

parameters:
            host TYPE string lower case default 'evatr.bff-online.de',
            service TYPE string default '0080',
            path TYPE string lower case default '/evatrRPC',
            protocol type string default 'HTTP/1.0',
            query type string lower case default 'UstId_1=DE246333056&UstId_2=IT01412080507&Firmenname=&Ort=&PLZ=&Strasse=&Druck='.



CALL METHOD cl_http_client=>create
  EXPORTING
    host               = host
    service            = service
    proxy_host         = 'gs-proxy'
    proxy_service      = '80'
    scheme             = 1
  IMPORTING
    client             = client
  EXCEPTIONS
    argument_not_found = 1
    internal_error     = 2
    plugin_not_active  = 3
    OTHERS             = 4.


IF sy-subrc <> 0.
  WRITE: / 'Create failed, subrc = ', sy-subrc.
  EXIT.
ENDIF.




CALL METHOD client->request->set_method(
  if_http_request=>co_request_method_get ).


IF protocol = 'HTTP/1.0'.
  client->request->set_version(
       if_http_request=>co_protocol_version_1_0 ).
ELSE.
  client->request->set_version(
       if_http_request=>co_protocol_version_1_1 ).
ENDIF.

  dummy = 'on'.
  client->request->set_form_field( name = 'statistic'
                                   value = dummy ).

dummy = path.
cl_http_utility=>set_request_uri( request = client->request
                               uri     = dummy ).


    data: l_fields type tihttpnvp.
    dummy = query.
    l_fields = cl_http_utility=>string_to_fields(
                      string  = dummy
                      encode  = 0 ).
    client->request->set_form_fields( fields = l_fields ).

*cl_http_utility=>set_query( request = client->request
*                               query     = query ).

subrc = cl_http_utility=>get_last_error( ).
if subrc <> 0.
    format color col_background.
    write: / 'Wrong URI format'.
    exit.
endif.

CALL METHOD client->send
  EXPORTING
    timeout                    = timeout
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    OTHERS                     = 4.






IF sy-subrc <> 0.
  CALL METHOD client->get_last_error
    IMPORTING
      code    = subrc
      MESSAGE = errortext.
  WRITE: / 'communication_error( send )',
         / 'code: ', subrc, 'message: '.
  EXIT.
ENDIF.




CALL METHOD client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    OTHERS                     = 4.

IF sy-subrc <> 0.
  CALL METHOD client->get_last_error
    IMPORTING
      code    = subrc
      MESSAGE = errortext.
  WRITE: / 'communication_error( receive )',
         / 'code: ', subrc, 'message: '.
  EXIT.
ENDIF.

    format color col_group intensified off.

    data: fields type tihttpnvp,
          fields_wa type ihttpnvp.

    call method client->response->get_header_fields
           changing fields = fields.

perform write_document.



CALL METHOD client->close
  EXCEPTIONS
    http_invalid_state = 1
    OTHERS             = 2.





*&---------------------------------------------------------------------*
*&      Form  write_document
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form write_document .
  data: data type string.
  data: l_width type i,   "length of line
        l_width_f type i, "length of field name output
        l_width_v type i, "length of field value output
        l_width_b type i, "length of body line output
        l_width_h type i. "length of field value for multi-line output
  data: line(142) type c, "must be of length = l_width_b
      len type i,
      llen type i.
  data: l_lvalue type flag. "flag for multi-line output.

* init values for output length
  l_width = 145.
  l_width_f = 40.
  l_width_v = 100.
  l_width_b = 142.
  l_width_h = l_width_f + l_width_v.

  write: / sy-uline(l_width) no-gap.
* title
  format color col_normal intensified on.
  write: / sy-vline no-gap,
     at (l_width_b) 'header fields ' centered.
  write: sy-vline no-gap.
  write: / sy-uline(l_width) no-gap .

* check length of field values
  loop at fields into fields_wa.
    len = strlen( fields_wa-value ).
    if len gt l_width_v.
      l_lvalue = 'X'.
      exit.
    endif.
  endloop.

* table header
  if l_lvalue is initial.
    format color col_heading intensified on.
    write: / sy-vline no-gap,
       at (l_width_f) 'field name' , sy-vline no-gap,
       at (l_width_v) 'field value' ,
           sy-vline no-gap.
    write: / sy-uline(l_width) no-gap.

    format color col_normal intensified off.
    loop at fields into fields_wa.
      write: / sy-vline no-gap, at (l_width_f) fields_wa-name ,
             sy-vline no-gap, at (l_width_v) fields_wa-value ,
             sy-vline .
    endloop.
    write: /  sy-uline(l_width) no-gap.
  else.
* multi-line output for header field values
* table header
    format color col_heading intensified on.
    write: / sy-vline no-gap,
         at (l_width_b) 'field name' , sy-vline no-gap.
    write: / sy-vline no-gap,
       at 4(l_width_h) 'field value' ,
       sy-vline no-gap.
    write: / sy-uline(l_width) no-gap.

  data: l_int_flag type c.
  format color col_normal.
  loop at fields into fields_wa.
    if l_int_flag is initial.
      format intensified off.
      l_int_flag = 'X'.
    else.
      format intensified on.
      clear l_int_flag.
    endif.
    write: / sy-vline no-gap, at (l_width_b) fields_wa-name ,
           sy-vline no-gap.
    len = strlen( fields_wa-value ).
    while len > l_width_h.
      write: / sy-vline no-gap, at 4(l_width_h) fields_wa-value ,
         sy-vline no-gap.
      fields_wa-value = fields_wa-value+l_width_h.
      len = strlen( fields_wa-value ).
    endwhile.
    write: / sy-vline no-gap, at 4(l_width_h) fields_wa-value ,
       sy-vline no-gap.
  endloop.
  write: /  sy-uline(l_width) no-gap.

  endif.
* output data



  data = client->response->get_cdata(  ).
  len = strlen( data ).

  write: / sy-uline(l_width) no-gap.
  format color col_heading intensified off.
  write: / sy-vline, at (l_width_b) 'body' .
  write at l_width sy-vline.
  format color col_normal intensified off.
  while len > 0.
    line  = data+llen(*).
    write: / sy-vline no-gap.
    write:  line.
    write at l_width sy-vline.
    len = len - l_width_b.
    llen = llen + l_width_b.
  endwhile.
  if llen < len.
    write: / sy-vline.
    line  = data+llen(*).
    write at l_width sy-vline.
    write:  line.
  endif.

  write: / sy-uline(l_width) no-gap.
endform.                    " write_document

Re: HTTP Kommunikation

Beitrag von macjam (ForumUser / 8 / 0 / 0 ) »
Hallo und danke
Ich hätte da einen anderen Code eben erst bekommen
der ist viel kürzer und funktioniert auch gibts da probleme also zumbeispiel mit stabilität und so...

Code: Alles auswählen.

parameters: p_mail(100) lower case.                 " E-Mail id to be verified
data: http_client type ref to if_http_client .
data: w_string type string ,
      w_result type string ,
      r_str    type string .
data: result_tab type table of string.
start-of-selection .
  clear w_string .
  concatenate
  'HTTP://WWW.' p_mail
 into
  w_string .
  call method cl_http_client=>create_by_url
    exporting
      url                = w_string
    importing
      client             = http_client
    exceptions
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      others             = 4.
  call method http_client->send
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2.
  call method http_client->receive
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.
  clear w_result .
  w_result = http_client->response->get_cdata( ).
  refresh result_tab .
  split w_result at cl_abap_char_utilities=>cr_lf into table result_tab .
  read table result_tab into r_str index 2.

Seite 1 von 1

Vergleichbare Themen

10
Antw.
6176
Views
HTTP-Kommunikation zwischen RFID-Gerät und SAP AII
von Mero » 19.07.2005 09:57 • Verfasst in Exchange Infrastructure
2
Antw.
1790
Views
Kommunikation aus SAP direkt mit SPS
von Helmut Rückert » 15.10.2008 15:45 • Verfasst in ABAP® Core
0
Antw.
2201
Views
Kommunikation SAP mit ASP-Seite
von gdc » 24.11.2006 18:59 • Verfasst in Java & SAP®
0
Antw.
3321
Views
Kommunikation SAP mit ASP-Seite
von gdc » 24.11.2006 18:59 • Verfasst in Exchange Infrastructure
0
Antw.
929
Views
Kommunikation SAP mit ASP-Seite
von gdc » 20.11.2006 17:49 • Verfasst in ABAP® Core

Über diesen Beitrag


Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.