cancel
Showing results for 
Search instead for 
Did you mean: 

Authentication error when using CL_HTTP_CLIENT

0 Kudos

Hi all,

I'm using an instruction from the blog of Thomas Jung to get an image from the content server into the cache of the ICM framework. See this [blog Thomas Jung|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417200)ID0623211050DB12910368107152505592End?blog=/pub/wlg/1012].

See also this thread: [|https://forums.sdn.sap.com/]

At the point where I want to receive the response I currently get a popup where I'm asked to logon. Probably logon to the contentserver. I get this logon when the authentication on the content server is swithed on. Evwerything works fine when this authentication is switched off.

I want to know how I can set this authentication in my instance of CL_HTTP_CLIENT in order to make the receive of the image working fine.

Has anybody ever faced the same issue?

Regards,

Joost

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You have two choices.

1. You can feed the authentication into the CL_HTTP_CLIENT instance using the authenticate method:

call method cl_http_client=>create
    exporting
      host               = me->ls_login_info-url
      service            = me->c_http_service_port
      scheme             = cl_http_client=>schemetype_http
    importing
      client             = me->http_client
    exceptions
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      others             = 4.

   me->http_client->propertytype_logon_popup = me->http_client->co_disabled.
    data l_username type string.
    data l_password type string.
    l_username = 'MyUser'
    l_password = 'MyPassword'.
    call method me->http_client->authenticate
      exporting
        username             = l_username
        password             = l_password.

2. Second option is to use HTTP destinations from SM59. This is a bit more managable since the password is maintained in the SM59 configuration and encrypted for you.

cl_http_client=>create_by_destination(
    exporting
      destination              = c_destination    " Logical destination (specified in function call)
    importing
      client                   = r_api->http_client  " HTTP Client Abstraction
    exceptions
      argument_not_found       = 1
      destination_not_found    = 2
      destination_no_authority = 3
      plugin_not_active        = 4
      internal_error           = 5
      others                   = 6 ).

0 Kudos

Hi Thomas,

Thanks for your reply. I was also already thinking of the authentication method, but realized I would face continuity problems when password etc. change on the content server.

I currently use the method CREATE_BY_URL to instantiate the CL_HTTP_CLIENT. If I would use the create_by_desitnation, how would I combine this with my url that is pointing to the place of the document on the content server?

Regards,

Joost van Poppel

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

In the HTTP Destination in SM59 only maintain the hostname and the port. Just place / in the path prefix. You can supply the rest of the URL via the request SET_HEADER_FIELD method with the field ~request_uri.

me->http_client->request->set_header_field(
     name  = me->c_request_uri                            "Constant with Value: ~request_uri
     value = me->c_api_update_dataset && `/` && i_session_id ).

0 Kudos

Hi Thomas,

Thanks for your reply. I now have both options ready in the right system, but I'm waiting for somebody who knows the right credentials of the content repository to create an HTTP RFC-dest in SM59. I know the host and port, but I need somebody to tell me the logon credentials to this content repository, in order to fully create the RFC.

I suppose after this it will work, but I cannot test it yet. Will keep you informed.

Regards,

Joost

0 Kudos

Hi Thomas,

Me problem is solved now. In constantly faced some "orgnizational hurdles" when trying to get credentials for creating an RFC (to put it delicately). But I found another way of creating the URL to the contentserver. Via the service sap/bc/contentserver/ I concatenate a URL as follows:

 CONCATENATE 'http://' sy-host 'domain:port/sap/bc/contentserver/' sy-mandt '?' 

After that I finish the rest of the URL by concatenating the pointer to the document after the ? in the above URL.

The I create the http_client as you described in your blog via the create_by_url, followed by all the other steps.

To use the service "contentsever" in SICF as described above, you need to create an external alias in SICFwhere you specify the logon data based upon a systemuser.

Thanks for thinking with me!

Regards,

Joost

P.S. Enjoyed your session in Vienna about new WD4A functionality...very nice stuff coming up!!! Didn't talk to you anymore...maybe next time.