I have some problems to send a PDF FILE to a http server using if_http_client class with for example methods :
CALL METHOD client->request->set_header_field
CALL METHOD client->send
CALL METHOD client->receive
I dont want to use FM SO_NEW_DOCUMENT_ATT_SEND_API1, SO_NEW_DOCUMENT_ATT_SEND_MAPI , SO_NEW_DOCUMENT_SEND_API1
Could someone please give me a sample abap program doing this ?
It could be great.
Thanks
Welcome to SDN.
1. upload the pdf file to a itab using GUI_UPLOAD (file type 'BIN') ( i assume that you are doing this abap program and not in BSP page)
2. create a instance of cl_http_client
call method cl_http_client=>create
exporting
host = 'www.server.com'
service = '80'
scheme = '1'
importing
client = http_client.
3. set header fields.
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 = 'HTTP/1.1'.
call method http_client->request->set_header_field
exporting
name = 'Content-Type'
value = 'application/pdf' .
call method http_client->request->set_data
exporting
data = <xstring holding the uploaded content>
offset = 0
length = rlength.
call method http_client->request->set_header_field
exporting
name = 'Content-Length'
value = txlen.
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 wf_string1 .
wf_string1 = http_client->response->get_cdata( ).
Hope this is clear.
Regards
Raja
Message was edited by: Durairaj Athavan Raja
A snippet of code that works for me.
response->set_header_field( name = 'content-type'
value = 'application/pdf' ).
some Browsers have caching probs when loading PDF
response->set_header_field(
name = 'cache-control'
value = 'max-age=0' ).
l_pdf_xstring contains PDF data
l_pdf_len = XSTRLEN( l_pdf_xstring ).
response->set_data( data = l_pdf_xstring
length = l_pdf_len ).
navigation->response_complete( ).
End of code
I am pretty sure SAP delivers an example that runs a smartform via a BSP and reders it as a PDF. Can't seem to find it though.
Cheers
Graham Robbo
Add a comment