Code: Alles auswählen.
method if_http_client~authenticate.
* ...
pf_m_open c_statistic_state 'HTTP Basic Authentication'. "#EC *
if proxy_authentication <> 'X'.
m_username = username.
m_password = password.
m_client = client.
m_language = language.
m_is_password_encrypted = ABAP_FALSE.
endif.
m_patch = 0.
if proxy_authentication <> 'X'.
call method request->set_authorization
EXPORTING
username = m_username
password = m_password.
else.
if m_target_scheme = schemetype_http.
m_is_proxy_password_encrypted = ABAP_FALSE.
* -- proxy logon only for http protocol
data: l_utility type ref to if_http_utility.
data: logon type string,
logon_b64 type string.
create object l_utility type cl_http_utility.
concatenate username ':' password into logon.
logon_b64 = l_utility->encode_base64( logon ).
concatenate 'Basic' logon_b64 into logon_b64 "#EC NOTEXT
separated by space.
call method request->set_header_field
EXPORTING
name = 'Proxy-Authorization' "#EC NOTEXT
value = logon_b64.
else.
if c_client_kernel_version < 5.
m_is_proxy_password_encrypted = ABAP_TRUE.
data: l_password_encrypted(128) type c,
l_password_original(64) type c.
* -- proxy logon via SSL layer
m_proxy_username = username.
l_password_original = password.
* -- encryption of proxy password in case of SSL communication
* -- for usage in kernel in FM 'HTTP_WRITE_SC'
call 'RFCControl' "#EC CI_CCALL
id 'CODE' field 'v'
id 'SOURCE' field l_password_original
id 'DESTINATION' field l_password_encrypted.
m_proxy_password = l_password_encrypted.
else.
m_proxy_username = username.
m_proxy_password = password.
m_is_proxy_password_encrypted = abap_false.
endif.
endif.
endif.
" call method authentication.
if not m_client is initial.
data: l_client type string.
l_client = m_client.
call method request->set_header_field
EXPORTING
name = 'SAP-Client' "#EC NOTEXT
value = l_client.
endif.
if not m_language is initial.
data: l_language type string.
l_language = m_language.
call method request->set_header_field
EXPORTING
name = 'SAP-Language' "#EC NOTEXT
value = l_language.
endif.
pf_m_close c_statistic_state 'HTTP Basic Authentication'. "#EC *
endmethod. "
Code: Alles auswählen.
IF o_client IS BOUND.
* Anmeldedaten übermitteln
o_client->authenticate( username = ''
password = '' ).
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
rob_abc