Skip to Content
0
May 14, 2012 at 12:01 PM

How to change the Host during CL_HTTP_CLIENT session

1617 Views

I am trying to communicate with a Cloud service ( http://api.cospace.de ) using class CL_HTTP_CLIENT.

My problem is that I need to change the host name during the communication. (A similar problem can be found CL_HTTP_CLIENT authentication and data hosts are not same but was not solved in ABAP there).

The REST interface needs to be addressed this way:

  1. GET https://api.cospace.de/api/session you get a server name and a session id as answer
  2. POST https://api01.cospace.de/api/session now you use host api01.cospace.de (or api02.cospace.de) for authenticating the session that started in step 1

In ABAP I use cl_http_client=>create_by_url for step 1 and do the GET command. Now I need to change the host for the POST command in step 2.

I tried to use

call method ro_api->o_client->request->set_header_field    exporting      name  = '~host'      value = 'api01.cospace.de'.

but this does not seem to work.

Could this work in general? In Python you would change the socket of the http client for doing this. But is anything similar possible in ABAP?