07-16-2007 2:07 AM
Hi all,
I'm having some problems trying to call a credit card https web service from ABAP on 2004s SP11. I'm not using a proxy server and a call from a test https page on my local machine works fine. The page does not require a certificate.
Do I need to do anything in particular to make https work ? I've done calls to http services without any problems. The only difference from a programming perspective as far as I know is the scheme 2 instead of 1, and the server protocol changed to HTTPS.
All is fine until I call method http_client->receive, at that point I get a return code of 1, http_communication_failure.
Your suggestions & contributions will be greatly appreciated.
Cheers,
Wouter.
report zcreditcardtest .
data: wf_user type string .
data: wf_password type string .
data: rlength type i,
txlen type string .
data: http_client type ref to if_http_client .
data: wf_string type string .
data: wf_string1 type string .
data: wf_proxy type string ,
wf_port type string .
selection-screen: begin of block a with frame .
parameters: crcard(16) type c lower case default '4242424242424242',
cvn(4) type c lower case default '564',
year(2) type c lower case default '07',
month(2) type c lower case default '11',
amount(10) type c lower case default '100.00',
cukey(4) type c lower case default 'AUD',
order(10) type c lower case default 'AB1322-refund'.
selection-screen skip 1.
parameters: user(50) lower case,
password(50) lower case ,
p_proxy(100) lower case default '' ,
p_port(4) default ''.
selection-screen: end of block a .
at selection-screen output.
loop at screen.
if screen-name = 'PASSWORD'.
screen-invisible = '1'.
modify screen.
endif.
endloop.
start-of-selection .
clear wf_string .
concatenate
'order.type=capture&customer.username=SOMEUSER'
'&customer.password=SOMEPASSWORD'
'&customer.merchant=SOMEMERCHANT'
'&card.PAN=' crcard
'&card.CVN=' cvn
'&card.expiryYear=' year
'&card.expiryMonth=' month
'&order.amount=' amount
'&customer.orderNumber=' order
'&card.currency=' cukey
'&order.ECI=IVR'
'&customer.captureOrderNumber=' order
'&order.priority=1'
'&message.end=null'
into wf_string .
break-point.
clear :rlength , txlen .
rlength = strlen( wf_string ) .
move: rlength to txlen .
clear: wf_proxy, wf_port .
move: p_proxy to wf_proxy ,
p_port to wf_port .
call method cl_http_client=>create
exporting
host = 'api.somewhere.com'
service = '80'
scheme = '2' "https
proxy_host = wf_proxy
proxy_service = wf_port
importing
client = http_client.
http_client->propertytype_logon_popup = http_client->co_disabled.
wf_user = user .
wf_password = password .
* proxy server authentication
call method http_client->authenticate
exporting
proxy_authentication = 'X'
username = wf_user
password = wf_password.
call method http_client->request->set_header_field
exporting
name = '~request_method'
value = 'POST'.
call method http_client->request->set_header_field
exporting
name = '~server_protocol'
value = 'HTTPS/1.0'.
call method http_client->request->set_header_field
exporting
name = '~request_uri'
value = '/post/CreditCardAPIReceiver'.
call method http_client->request->set_header_field
exporting
name = 'Content-Type'
value = 'application/x-www-form-urlencoded; charset=UTF-8'.
call method http_client->request->set_header_field
exporting
name = 'Content-Length'
value = txlen.
call method http_client->request->set_header_field
exporting
name = 'HOST'
value = 'api.somewhere.com:80'.
call method http_client->request->set_cdata
exporting
data = wf_string
offset = 0
length = rlength.
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.
if sy-subrc <> 0.
message e000(oo) with 'Processing failed !'.
endif.
clear wf_string1 .
wf_string1 = http_client->response->get_cdata( ).
* Further Processing of returned values would go here.
07-16-2007 3:31 AM
A little more information for my question, I'm trying to achieve the following POST :
POST /post/CreditCardAPIReceiver HTTPS/1.0
Content-type: application/x-www-form-urlencoded; charset=UTF-8
Content-length: 315
Host: api.somewhere.com:80
order.type=capture&customer.username=COMPANYA&customer.pas
sword=insurance&customer.merchant=companya&card.PAN=424242
4242424242&card.CVN=564&card.expiryYear=10&card.expiryMont
h=06&order.amount=3400&customer.orderNumber=AB1322refund&c
ard.currency=AUD&order.ECI=IVR&customer.captureOrderNumber
=AB1322&order.priority=1&message.end=null
Host name has been changed for security purposes.
07-16-2007 5:17 AM
Hi,
I have not used HTTPS post, but in a test program I used for HTTP I note there is a '~request_protocol' header field (value "HTTP/1.0").
You can also try the following after the send / receive that fails to get extra details
CALL METHOD http_client->get_last_error
IMPORTING
message = my_message. "type string
Andrew
07-16-2007 9:27 AM
Hi Andrew,
Thanks for the tips, no luck unfortunately. The last message as suggested is blank... I believe this has something to do with certificates and trusted systems. I've seen some posts on using RFC destinations instead of going straight out, I might have a look at that.
Unfortunately this is new to me so I will have to keep digging...
Thanks anyway,
Wouter.
07-16-2007 3:32 PM
Well, finally got this running !
First of all I needed to download SAP Cryptographic Software and install it on the Web Application Server. Added some parameters to the profile, then set up some nodes in strust. Note 510007 describes the full process.
I then installed the certifcate I needed by opening the website in internet explorer and exporting it to a CER file and then importing it into the SSL client (Anonymous). The blog from Thomas Yung, "BSP a Developer's Journal Part XIV - Consuming WebServices with ABAP" describes the process of exporting and importing certificates.
I then had to start the HTTPS service on my NW 2004s ABAP preview edition SP11. I set this up for port 443.
/osmicm --> GOTO --> SERVICES --> SERVICE --> CREATE
Then finally, the program needed a few changes :
call method cl_http_client=>create
exporting
host = 'api.somewhere.com'
service = '443' " <<----- 443 NOT 80
scheme = '2' "https
ssl_id = 'ANONYM' " <<----- SSL_ID Added
proxy_host = wf_proxy
proxy_service = wf_port
importing
client = http_client.
and further in the program (thanks Andrew !) :
call method http_client->request->set_header_field
exporting
* name = '~server_protocol' " <<<--- DELETE
name = '~request_protocol' " <<<-- INSERT must be request
value = 'HTTPS/1.0'.
and presto, we can now consume a https webservice via a POST method from within an ABAP program ! Nice.... Can I give myself 10 points ?
09-16-2013 8:02 AM
06-19-2015 7:27 PM
Hi Wouter,
I'm facing a similar issue. Can you explain me a little bit more how wf_string and host have to poputate ??
Thanks in advance
Have a nice day.
02-14-2020 4:17 PM
Hi,
an additional question:
Variable "wf_string" which will be POSTED In this example.
Does this "wf_string" has a limit?
If yes, what is the maximal length for the POST-request?
thanks Joachim