04-07-2010 9:12 AM
Hello!
I need some help. I have a php-filename ( http:
www.site.com\values.php?date=2009-10-21&value=1234 ).
The data (date and value) I get from a SAP table. That means, I concatenate the script name in SAP.
Now I have to run this file (or script?) automatically in SAP (in background).
But I can't find a method to do this.
Kind Regards
Ramona
04-07-2010 12:07 PM
Hi,
You may try to use class httpclient as follows:
DATA: http_client TYPE REF TO if_http_client .
DATA: l_url TYPE string ,
l_result TYPE string ,
l_str TYPE string .
DATA: lt_results TYPE TABLE OF string.
CLEAR l_url .
CONCATENATE 'http:\\www.site.com\values.php?date=' '2009-10-21' '&value=' '1234'
INTO
l_url .
CALL METHOD cl_http_client=>create_by_url
EXPORTING url = l_url
IMPORTING client = http_client
EXCEPTIONS argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
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 l_result .
l_result = http_client->response->get_cdata( ).
REFRESH lt_results .
SPLIT l_result AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_results .
LOOP AT lt_results INTO l_str.
WRITE:/ l_str .
ENDLOOP .
04-07-2010 12:07 PM
Hi,
You may try to use class httpclient as follows:
DATA: http_client TYPE REF TO if_http_client .
DATA: l_url TYPE string ,
l_result TYPE string ,
l_str TYPE string .
DATA: lt_results TYPE TABLE OF string.
CLEAR l_url .
CONCATENATE 'http:\\www.site.com\values.php?date=' '2009-10-21' '&value=' '1234'
INTO
l_url .
CALL METHOD cl_http_client=>create_by_url
EXPORTING url = l_url
IMPORTING client = http_client
EXCEPTIONS argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
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 l_result .
l_result = http_client->response->get_cdata( ).
REFRESH lt_results .
SPLIT l_result AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_results .
LOOP AT lt_results INTO l_str.
WRITE:/ l_str .
ENDLOOP .
04-08-2010 9:06 AM
Hello Simo,
running as a background job is the same result as written.
What could be the reason for the error message?
Kind Regards
Ramona
04-08-2010 11:37 AM
You need to talk to your network people to find out how to get out to the internet
CALL METHOD cl_http_client=>create_by_url
EXPORTING url = l_url
proxy_host = proxy.xxx.com ???!!!
proxy_service = 80 ???!!!
IMPORTING client = http_client
EXCEPTIONS argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
04-08-2010 1:21 PM
Hi Simo,
We made progress in solving the problem.
Now I get the error
HTTP message has an invalid format. Contact your system administrator
I searched for that error, but I couldn't find a solution for it.
Can you help me again, please?
Thanks very much for your help.
Kind Regards
Ramona
The method calls all did return with code 0:
CALL METHOD cl_http_client=>create_by_url, sy-subrc = 0
CALL METHOD cl_http_client->send, sy-subrc = 0
CALL METHOD cl_http_client->receive, sy-subrc = 0
Edited by: Ramona Wolf on Apr 8, 2010 2:30 PM
04-08-2010 3:14 PM
Insert code below before CALL METHOD http_client->send
DATA: form_data type tihttpnvp.
DATA: line type ihttpnvp.
call method http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
line-name = 'date'.
line-value = '2009-10-21'.
APPEND line to form_data.
line-name = 'value'.
line-value = '1234'.
APPEND line to form_data.
call method http_client->request->set_form_fields
EXPORTING
fields = form_data.
04-09-2010 8:01 AM
Hello Simo,
now I get the following error:
09 Apr 2010 08:50:40
Error Message: Badly formed request - No path or hostname in request. Your
Information: The HTTP message has an invalid format. Contact your system administrator.
This is my source code:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url
proxy_host = '172.16.0.55'
proxy_service = '8080'
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
WRITE: / 'CALL METHOD cl_http_client=>create_by_url, sy-subrc = ', sy-subrc.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
call method http_client->request->set_method(
if_http_request=>co_request_method_get ).
CALL METHOD http_client->refresh_cookie
EXCEPTIONS
http_action_failed = 1
http_processing_failed = 2
OTHERS = 3.
WRITE: / 'CALL METHOD cl_http_client->refresh_cookie, sy-subrc = ', sy-subrc.
CALL METHOD http_client->refresh_request
EXCEPTIONS
http_action_failed = 1
OTHERS = 2.
WRITE: / 'CALL METHOD cl_http_client->refresh_request, sy-subrc = ', sy-subrc.
CALL METHOD http_client->refresh_response
EXCEPTIONS
http_action_failed = 1
OTHERS = 2.
WRITE: / 'CALL METHOD cl_http_client->refresh_response, sy-subrc = ', sy-subrc.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
WRITE: / 'CALL METHOD cl_http_client->send, sy-subrc = ', sy-subrc.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
WRITE: / 'CALL METHOD cl_http_client->receive, sy-subrc = ', sy-subrc.
ULINE.
CLEAR l_result .
l_result = http_client->response->get_cdata( ).
REFRESH lt_results .
SPLIT l_result AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_results .
WRITE: / sy-datum, ': ', / l_url.
LOOP AT lt_results INTO l_str.
WRITE:/ l_str .
ENDLOOP .
How you can see, I tried several ways to run.
I can't find a solution.
I tried with l_url is the full path name and I tried it without the data.
What do I wrong?
thanks for your help!
Kind Regards
Ramona
04-09-2010 12:23 PM
I quess HTTP request still does not contain all the header fields needed.
Add the fields below and learn more from http://php.net/manual/en/reserved.variables.server.php
call method http_client->request->request->set_header_field
exporting name = '~request_uri'
value = '/path/values.php' .
call method http_client->request->request->set_header_field
exporting name = '~request_method'
value = 'POST'.
call method http_client->request->request->set_header_field
exporting name = '~enctype'
value = 'multipart/form-data'.
call method http_client->request->request->set_header_field
exporting name = 'Content-Type'
value = 'text/plain'.
call method http_client->request->request->set_header_field
exporting name = '~server_protocol'
value = 'HTTP/1.1'.
call method http_client->request->request->set_header_field
exporting name = '~Content-Length'
value = '60000' .
04-12-2010 9:15 AM
Hello Simo,
when running:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url
proxy_host = '172.xxx'
proxy_service = '8080'
I get the error: HTTP message has an invalid format. Contact your system administrator.
When running
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url
I get the error: 404 Resource not found. Partner not reached.
Could it be a missing authority?
Could you please check my source code? Perhaps I've done anything wrong.
Thank you very much!
Kind Regards Ramona
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url
proxy_host = '172XXX
proxy_service = '8080'
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
WRITE: / 'CALL METHOD cl_http_client=>create_by_url, sy-subrc = ', sy-subrc.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~request_uri'
VALUE = '/path/values.php' .
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~request_method'
VALUE = 'POST'.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~enctype'
VALUE = 'multipart/form-data'.
CALL METHOD http_client->request->set_header_field
EXPORTING name = 'Content-Type'
VALUE = 'text/plain'.
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-Length'
VALUE = '60000' .
line-name = 'date'.
line-value = c_sy_date.
APPEND line TO form_data.
line-name = 'value'.
line-value = c_mrate.
APPEND line TO form_data.
CALL METHOD http_client->request->set_form_fields
EXPORTING
fields = form_data.
CALL METHOD http_client->refresh_cookie
EXCEPTIONS
http_action_failed = 1
http_processing_failed = 2
others = 3.
WRITE: / 'CALL METHOD cl_http_client->refresh_cookie, sy-subrc = ', sy-subrc.
CALL METHOD http_client->refresh_request
EXCEPTIONS
http_action_failed = 1
others = 2.
WRITE: / 'CALL METHOD cl_http_client->refresh_request, sy-subrc = ', sy-subrc.
CALL METHOD http_client->refresh_response
EXCEPTIONS
http_action_failed = 1
others = 2.
WRITE: / 'CALL METHOD cl_http_client->refresh_response, sy-subrc = ', sy-subrc.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
WRITE: / 'CALL METHOD cl_http_client->send, sy-subrc = ', sy-subrc.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
WRITE: / 'CALL METHOD cl_http_client->receive, sy-subrc = ', sy-subrc.
ULINE.
CLEAR l_result .
l_result = http_client->response->get_cdata( ).
04-12-2010 2:04 PM
Add host and proper path if you got error Message: Badly formed request - No path or hostname in request.
* replace site.com with your site (http:\\www.site.com -> site.com)
call method http_client->request->set_header_field
exporting name = 'HOST'
value = 'site.com:8080'.
* replace 'path' with a proper path or just /values.php
call method http_client->request->request->set_header_field
exporting name = '~request_uri'
value = '/path/values.php' .
Try to get the http trace from your php server to find out all the header fields the site expects.
example:
HEAD / HTTP/1.1
Host: google.com
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; InfoPath.2)
Referer: http://www.rexswain.com/httpview.html
Connection: close
04-26-2010 7:02 AM
Dear Simo,
it's almost finished. There is no error message any more, but the website is not updated.
I'll try to find out the parameter which has to be set, but can you help me one more time?
Thank you very much!
This is my code:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'http://www.site.de'
proxy_host = '172.xx.xx.xx'
proxy_service = '8080'
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
WRITE: / 'CALL METHOD cl_http_client=>create_by_url, sy-subrc = ', sy-subrc.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~request_method'
VALUE = 'POST'.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~enctype'
VALUE = 'multipart/form-data'.
CALL METHOD http_client->request->set_header_field
EXPORTING name = 'Content-Type'
VALUE = 'text/html'.
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-Length'
VALUE = '60000' .
replace site.com with your site (http:
www.site.com -> site.com)
CALL METHOD http_client->request->set_header_field
EXPORTING name = 'HOST'
VALUE = 'site.de:8080'.
replace 'path' with a proper path or just /values.php
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~request_uri'
VALUE = '/page/value.php'.
line-name = 'date'.
line-value = c_sy_date.
APPEND line TO form_data.
line-name = 'value'.
line-value = c_mrate.
APPEND line TO form_data.
CALL METHOD http_client->request->set_form_fields
EXPORTING
fields = form_data.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
WRITE: / 'CALL METHOD cl_http_client->receive, sy-subrc = ', sy-subrc.
ULINE.
CLEAR l_result .
l_result = http_client->response->get_cdata( ).
Kind Regards
Ramona
04-26-2010 8:14 AM
Hi,
Have you forgot this:
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
It should be before CALL METHOD http_client->receive
Also add the following to see the results at the end:
REFRESH lt_results .
SPLIT l_result AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_results .
LOOP AT lt_results INTO l_str.
WRITE:/ l_str .
ENDLOOP .
04-26-2010 8:23 AM
Hi!
Both codes you sent are in my program, I deleted it in the message by an oversight.
Kind Regards
Ramona
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'http://www.site.de'
proxy_host = '172.xx.xx.xx'
proxy_service = '8080'
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
WRITE: / 'CALL METHOD cl_http_client=>create_by_url, sy-subrc = ', sy-subrc.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~request_method'
VALUE = 'POST'.
CALL METHOD http_client->request->set_method
EXPORTING
method = if_http_request=>CO_REQUEST_METHOD_GET.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~enctype'
VALUE = 'multipart/form-data'.
CALL METHOD http_client->request->set_header_field
EXPORTING name = 'Content-Type'
VALUE = 'text/html'.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~server_protocol'
VALUE = 'HTTP/1.1'.
CALL METHOD http_client->request->set_version
EXPORTING
version = if_http_request=>CO_PROTOCOL_VERSION_1_1.
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~Content-Length'
VALUE = '60000' .
replace site.com with your site (http:
www.site.com -> site.com)
CALL METHOD http_client->request->set_header_field
EXPORTING name = 'HOST'
VALUE = 'site.de:8080'.
replace 'path' with a proper path or just /values.php
CALL METHOD http_client->request->set_header_field
EXPORTING name = '~request_uri'
VALUE = '/page/values.php'.
"VALUE = '/values.php' .
line-name = 'date'.
line-value = c_sy_date.
APPEND line TO form_data.
line-name = 'value'.
line-value = c_mrate.
APPEND line TO form_data.
CALL METHOD http_client->request->set_form_fields
EXPORTING
fields = form_data.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
WRITE: / 'CALL METHOD cl_http_client->send, sy-subrc = ', sy-subrc.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
WRITE: / 'CALL METHOD cl_http_client->receive, sy-subrc = ', sy-subrc.
ULINE.
CLEAR l_result .
l_result = http_client->response->get_cdata( ).
REFRESH lt_results .
SPLIT l_result AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_results .
WRITE: / sy-datum, ': ', / l_url.
LOOP AT lt_results INTO l_str.
WRITE:/ l_str .
ENDLOOP .
04-29-2010 8:06 AM
Hi Simo,
thank you very much for your help.
Now it's running correctly.
Kind Regards Ramona
04-07-2010 2:02 PM
Hi Simo,
thanks for your quick help.
I tried it and run it in test as "running in background".
But there's been the error:
Application Server Error
404 Resource not found
Partner not reached
Error: -20
Version: 7000
Component:ICM
Date/Time: Wed Apr 07 13:17:03 2010
Module: icxxconn.c
Line: 2321
Server: SRVSAPC11_C11_00
Error Tag:
Detail: Connection request from (32/33/0) to host: , service: 80
I try it again and plan it as a job. Tomorrow I know the results.
Kind Regards
Ramona