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
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.