cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP AND PDF file download

Former Member
0 Kudos

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 don’t 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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

athavanraja
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

Thank you Raja for the answer,

Could you tell me more about :

wf_string1

rlength

txlen

Best regards

athavanraja
Active Contributor
0 Kudos

rlength is of type i and this will hold the lenght of the uploaded pdf content.

rlength is moved txlen because the method only accepts only char type variable.

wf_string1 is of type string and it will hold the message returned by the calling server.

check out this weblog where i have used this code.

/people/durairaj.athavanraja/blog/2004/09/20/consuming-web-service-from-abap

Hope this helps.

Regards

Raja

reward points by cliking the radiobutton for helpful answers. this is SDN way of saying thanks.

Former Member
0 Kudos

Thanks so lot, Raja, for your disponibility and your help,

See below the return status code I had from the HTTP SERVER after implementing the ABAP code :

**********************************************************

Error 406--Not Acceptable

From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:

10.4.7 406 Not Acceptable

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. Depending upon the format and the capabilities of the user agent, selection of the most appropriate choice may be performed automatically. However, this specification does not define any standard for such automatic selection.

Note: HTTP/1.1 servers are allowed to return responses which are not acceptable according to the accept headers sent in the request. In some cases, this may even be preferable to sending a 406 response. User agents are encouraged to inspect the headers of an incoming response to determine if it is acceptable. If the response could be unacceptable, a user agent SHOULD temporarily stop receipt of more data and query the user for a decision on further actions.

**********************************************************

Is there any other solution (other class, other methods) to do that because it 's not working or perhaps something wrong ?

Can you help me please.

TIA

athavanraja
Active Contributor
0 Kudos

is the receving server can accept pdf content. there is nothing wrong with your program, but you need to check with the receving server whether it can accept pdf.

and also check what kind of response they send.

you may need to use accept headers which is explained here

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Regards

Raja

Former Member
0 Kudos

Hello Raj,

there was a blog in which you and another friend had described how to output a PDF file which was built using a smartform in BSP using frames. It worked for me and I accidently deleted that piece of code.

Can Please..Please find that blog for me.

It will help me a lot.

Thanks,

Prasad

Former Member
0 Kudos

[BSP/HowTo: Generate PDF Output from a BSP.|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/bsp/pdf]

Regards,

Aaron