2013 Oct 14 5:58 PM
Hey guys,
I'm implementing a HTTPS client with ABAP. See my code below. If I work with HTTP everything is fine, but as soon I change to HTTPS, I get HTTP_COMMUNICATION_FAILURE in HTTP_CLIENT->RECEIVE.
Did I implement something wrong? Does HTTPS require some additional configuration? I already tried to add parameter ssl_id = 'ANONYM' to the method CL_HTTP_CLIENT=>CREATE.
Thanks and best regards
Oleksandr
DATA content TYPE string.
DATA url TYPE string.
DATA TPuser TYPE string.
DATA TPpassword TYPE string.
url = 'http://XX.XX.XX.XX:9000/'.
TPuser = 'user'.
TPpassword = 'password'.
" overwrite TP-User and TP-Password with corresponding encoded base64 values
DATA base64encoder TYPE REF TO cl_http_utility.
CREATE OBJECT base64encoder.
TPuser = base64encoder->if_http_utility~encode_base64( TPuser ) .
TPpassword = base64encoder->if_http_utility~encode_base64( TPpassword ) .
PERFORM sendRequest
USING url TPuser TPpassword
CHANGING content.
WRITE content.
FORM sendRequest USING url TYPE STRING
TPuser TYPE STRING
TPpassword TYPE STRING
CHANGING content TYPE STRING.
DATA HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT.
DATA utf8Content TYPE xstring.
DATA utf8Length TYPE i.
DATA tmpstr TYPE string.
DATA code TYPE i.
DATA reason TYPE string.
DATA l_request TYPE REF TO if_http_request.
CALL METHOD CL_HTTP_CLIENT=>CREATE_by_url
EXPORTING
URL = url
IMPORTING
CLIENT = HTTP_CLIENT.
CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = '~request_method'
VALUE = 'POST'.
tmpstr = utf8Length.
CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'Content-Length'
VALUE = tmpstr.
" Set TP-User and TP-Password
CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'TP-User'
VALUE = TPuser.
CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'TP-Password'
VALUE = TPpassword.
CALL METHOD HTTP_CLIENT->SEND
EXPORTING
timeout = 5000
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
HTTP_INVALID_TIMEOUT = 4
OTHERS = 5.
IF sy-subrc <> 0.
tmpstr = sy-subrc.
WRITE: 'HTTP communication failure (SEND failed: ', tmpstr, '); aborting.'.
HTTP_CLIENT->CLOSE( ).
EXIT.
ENDIF.
CALL METHOD HTTP_CLIENT->RECEIVE
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3.
IF sy-subrc <> 0.
tmpstr = sy-subrc.
WRITE: 'HTTP communication failure (RECV failed: ', tmpstr, '); aborting.'.
HTTP_CLIENT->CLOSE( ).
EXIT.
ENDIF.
CALL METHOD HTTP_CLIENT->RESPONSE->GET_STATUS
IMPORTING
code = code
reason = reason.
CLEAR: content.
"Read content data
utf8Content = HTTP_CLIENT->RESPONSE->GET_DATA( ).
IF code < 200 OR code >= 300.
tmpstr = code.
WRITE: 'HTTP communication failure (code:', tmpstr, '); aborting.'.
utf8Content = HTTP_CLIENT->RESPONSE->GET_DATA( ).
HTTP_CLIENT->CLOSE( ).
EXIT.
ELSE.
WRITE 'OK'.
ENDIF.
"Close client connection
HTTP_CLIENT->CLOSE( ).
ENDFORM.
2013 Oct 15 6:04 AM
Hypertext Transfer Protocol Secure (HTTPS) is a combination of two different protocols. It is more secure way to access the web. It is combination of Hypertext Transfer Protocol (HTTPS) and SSL/TLS protocol. It is more secure way to sending request to server from a client, also the communication is purely encrypted which means no one can know what you are looking for. This kind of communication is used for accessing those websites where security is required. Banking websites, payment gateway, emails (Gmail offers HTTPS by default in Chrome browser), and corporate sector websites are some great examples where HTTPS protocols are used.
For HTTPS connection, public key trusted and signed certificate is required for the server. These certificate comes either free or it costs few dollars depends on the signing authority. There is one other method for distributing certificates. Site admin creates certificates and loads in the browser of users. Now when user requests information to the web server, his identity can be verified easily.
Here are some major differences between HTTP and HTTPS:
| HTTP | HTTPS |
| URL begins with “http://” | URL begins with “https://” |
| It uses port 80 for communication | It uses port 443 for communication |
| Unsecured | Secured |
| Operates at Application Layer | Operates at Transport Layer |
| No encryption | Encryption is present |
| No certificates required | Certificates required |
MAY BE YOU ARE TRYING TO ACCESS A WEBSITE HAVING NO CERTIFICATE.
Try to browse the url in the browser there also it will create some issue.
Regards,
Alenlee MJ
2013 Oct 15 6:46 PM
Hello Alenlee,
thanks for the introduction into HTTPS. However, the webserver has a valid certificate and perfectly works, I checked with Postman, see a screenshot below.
Best regards
Oleksandr
2016 Jun 06 2:43 PM
Bit late but just found this while searching for something else. You will need to import the websites certificate into SAP using transaction STRUST.
Hope this makes sense but thought I'd write something rather than nothing
Cheers,
Tim J.