Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Multipart http post

Former Member
0 Likes
3,649

URGENT ISSUE -

Hi averyone

I need to make an upload of a file via POST method to a web service.

I have no problems passing the parameters user and password in the header line but i cant add multipart data to post de txt file .

the code im using is :

*create client object

CALL METHOD cl_http_client=>create

EXPORTING

host = host

service = port

scheme = scheme

IMPORTING

client = client.

*Set Header

client->request->set_header_field( name = '~request_uri'

value = path ).

client->request->set_header_field( name = '~request_method'

value = 'POST' ).

client->request->set_header_field( name = '~enctype'

value = 'multipart/form-data' ).

client->request->set_header_field( name = 'Content-Type'

value = 'text/plain').

client->request->set_header_field( name = '~server_protocol'

value = 'HTTP/1.1' ).

  • Set de los parametros a enviar

client->request->set_form_field( name = 'user'

value = '20295635089').

client->request->set_form_field( name = 'password'

value = '010107').

client->request->set_form_field( name = 'file'

value = 'c:\TB_20295635089_002002_20061212_000001.txt').

DATA: lv_fields TYPE tihttpnvp.

CALL METHOD client->request->get_header_fields

CHANGING

fields = lv_fields.

  • send and receive

client->send( ).

CALL METHOD client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3

OTHERS = 4.

Im getting the following error message

<HTML><TITLE>411 Invalid value for Content-Length header</TITLE><BODY><h1>411 Invalid value for Content-Length header</h1></BODY></HTML>

Ill look forward for some response .

13 REPLIES 13
Read only

Former Member
0 Likes
1,666

*create client object

CALL METHOD cl_http_client=>create

EXPORTING

host = host

service = port

scheme = scheme

IMPORTING

client = client.

*Set del Header

client->request->set_header_field( name = '~request_uri'

value = path ).

client->request->set_header_field( name = '~request_method'

value = 'POST' ).

client->request->set_header_field( name = '~enctype'

value = 'multipart/form-data' ).

client->request->set_header_field( name = 'Content-Type'

value = 'text/plain').

client->request->set_header_field( name = '~server_protocol'

value = 'HTTP/1.1' ).

client->request->set_header_field( name = '~Content-Length'

value = '60000' ).

client->request->set_form_field( name = 'user'

value = '20295635089').

client->request->set_form_field( name = 'password'

value = '010107').

client->request->set_form_field( name = 'file'

value = 'c:\TB_20295635089_002002_20061212_000001.txt').

  • send and receive

client->send( ).

CALL METHOD client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3

OTHERS = 4.

Read only

0 Likes
1,666

client->request->set_form_field( name = 'file'

value = 'c:\TB_20295635089_002002_20061212_000001.txt').

the above line is the problem.

you have to use gui_upload to upload the data first and then set it to the request object

request->set_cdata

then

request->send

Regards

Raja

Read only

0 Likes
1,666

client->request->set_form_field( name = 'file'

value = 'c:\TB_20295635089_002002_20061212_000001.txt').

the above line is the problem.

you have to use gui_upload to upload the data first and then set it to the request object

request->set_cdata

then

request->send

Regards

Raja

Read only

0 Likes
1,666

Sorry but i cant take this line out .

File is one of de obligatories parameters ..

if i upload de data and set it to the request object and take out the set_form_file = name = 'file' i get the error : parameter missing FILE .

thanks anyway .. hope you can help me with this.

Regards

Mcol

Read only

0 Likes
1,666

i am checking, will get back. however i feel that this may not be possible as the input type ="file" is very strict, you cannot even default file name to this element in normal html programming.

Regards

Raja

Read only

0 Likes
1,666

Hi Raja,

I know this is a very old thread but I have the same problem.  I need to send a parameter using set_form_field, because If I put it inside a multipart , the web site doesn't recognize it, but using method set_form_field, I don't know what value to pass, because the parameter is type file.

Do you know if there is a way to send a parameter type file , with set_form_field method?

Thansk,

Read only

Former Member
0 Likes
1,666

Hi ,

Even iam facing the same problem...Unexpected request Content-Type header 'application/x-www-form-urlencoded'....

i tried giving the content type properly.Not sure where is the problem.

Can you please help me out.

Meena

Read only

Former Member
0 Likes
1,666

Take the C:\ from that line and then use append_cdata and send.

Read only

0 Likes
1,666

Dear all, we are facing same issue, we are not able to send requested file as txt output format.

We sent user & password and input file as string. This is correct? Could you please send us an example?

Thanks in advance,

Read only

asdasd_asdasd
Active Participant
0 Likes
1,666

I found a way to make it work, please remove the username and password ARBA service you put: P

Read only

0 Likes
1,666

Dear Maxi,

could you please tell us how you send the username and password to ARBA? These are mandatory fields for HTTP Post conection.

Thanks in advance,

Daniela.

Read only

0 Likes
1,666

Create a new thread, and I'll explain what is happening ...

Read only

0 Likes
1,666

I'm already did it.

http://scn.sap.com/thread/3257799

Thanks in advance!