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

Need Help with HTTP_POST FM

Former Member
0 Likes
1,826

Hi Experts,

I have a requirement in which I have to send the xml data to a servlet from my ABAP program.I found that this can be achieved using HTTP_POST FM.I created a sample servlet and tried the FM.When I debugged the program the RESPONSE BODY is filled with characters similar to Chinese. (Please find the attachment).I guess I made some mistake while providing the import parameters to the FM.So it will be really helpful if someone provide a perfect example/instruction to use the FM properly.


Regards

Anoop 

1 ACCEPTED SOLUTION
Read only

rosenberg_eitan
Active Contributor
0 Likes
1,333

Hi,

I Duplicate RSHTTP20 to a local program the only change is:

Works also....

Regards.

5 REPLIES 5
Read only

custodio_deoliveira
Active Contributor
0 Likes
1,333

Hi Anoop,

If you believe you made a mistake on the import parameters, it would be helpful you you could share the code with us.

Cheers,

Custodio

Read only

0 Likes
1,333

Hi Custodio,

Thank you for the quick response.Please find the piece of code I have written below.

CONSTANTS: v_uri(100) VALUE 'http://xxx.xxx.x.xx:8080/WorkManager/LoginAuth'.

DATA: v_data(20) TYPE c VALUE 'Test String'.

APPEND v_data TO t_request_body.

v_len = strlen( v_data ).

APPEND 'UserAuth=testauth' TO t_request_header.

DATA: status_code(5),

status_text(300).

CALL FUNCTION 'HTTP_POST'

   EXPORTING

     absolute_uri                = v_uri

     request_entity_body_length  = v_len

*   RFC_DESTINATION             =

*   PROXY                       =

*   PROXY_USER                  =

*   PROXY_PASSWORD              =

*   USER                        =

*   PASSWORD                    =

*   BLANKSTOCRLF                =

   IMPORTING

     status_code                 = status_code

     status_text                 = status_text

*   RESPONSE_ENTITY_BODY_LENGTH =

   TABLES

     request_entity_body         = t_request_body

     response_entity_body        = t_response_body

     response_headers            = t_response_header

     request_headers             = t_request_header

exceptions

     connect_failed              = 1

     timeout                     = 2

     internal_error              = 3

     tcpip_error                 = 4

     SYSTEM_FAILURE              = 5

     COMMUNICATION_FAILURE       = 6

     OTHERS                      = 7.

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

Read only

rosenberg_eitan
Active Contributor
0 Likes
1,333

Hi,

I just did a small test.


Using program RSHTTP20

The program is using HTTP_GET

I have this Java prgram that use jetty http://www.eclipse.org/jetty/

I ran this using eclipse .

package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;

public class HelloWorld extends AbstractHandler {

public static void main(String[] args) throws Exception {
  final Server server = new Server(80);
  server.setHandler(new HelloWorld());
  server.start();
  server.join();
}

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
   throws IOException, ServletException {
  response.setContentType("text/html;charset=utf-8");
  response.setStatus(HttpServletResponse.SC_OK);
  baseRequest.setHandled(true);
  response.getWriter().println("<h1>Hello World</h1>");
}
}


On SAP:

Using program RSHTTP20


Regards.

Read only

rosenberg_eitan
Active Contributor
0 Likes
1,334

Hi,

I Duplicate RSHTTP20 to a local program the only change is:

Works also....

Regards.

Read only

0 Likes
1,332

Hi Eitan,

Thank you very much.I solved the issue by passing the  BLANKSTOCRLF  value as 'X'.

Regards

Anoop