Application Development 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: 

ABAP intergate with WeChat

former_member701231
Discoverer
375

Hi Experts,

Thank you very much for taking your time to review this issue.

In my case, I want to use ABAP development to achieve access to enterprise wechat. But always received the MSG 417 and failed: NIEHOST_UNKNOWN(-2) . I don't know if there is no configuration or what needs to be done.

Please help me.Thank you very much for your reply.

Here is my code:

  DATA: lo_http_client TYPE REF TO if_http_client,
        gv_json_out    TYPE string,
        lv_url         TYPE string,
        lv_auth        TYPE string,
        lv_head        TYPE string,
        lv_len         TYPE i,
        iv_json_input  TYPE string,
        ev_json_output TYPE string,
        l_content      TYPE char1024,
        l_value        TYPE savwctxt-fieldcont.

  DATA: l_sysubrc    TYPE sysubrc,
        l_error_text TYPE string.

  lv_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=xxxxx&corpsecret=xxxxx'.

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = lv_url
*     proxy_host         = 
*     proxy_service      = 
*     ssl_id             = 
*     sap_username       =
*     sap_client         = 
    IMPORTING
      client             = lo_http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.
  IF sy-subrc <> 0.
*               Implement suitable error handling here
  ENDIF.

  lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

  CALL METHOD lo_http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

  IF sy-subrc <> 0.

  ENDIF.

  CALL METHOD lo_http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.


  IF sy-subrc <> 0.
    CALL METHOD lo_http_client->get_last_error
      IMPORTING
        code    = l_sysubrc
        message = l_error_text.

    WRITE:/ l_sysubrc,
      / l_error_text.
  ENDIF.

  CLEAR ev_json_output.
  ev_json_output = lo_http_client->response->get_cdata( ).

  REPLACE ALL OCCURRENCES OF REGEX '\n' IN ev_json_output WITH space.

  IF ev_json_output IS INITIAL.
    WRITE: / 'faild'.
  ELSE.
    WRITE: / ev_json_output.
  ENDIF.
  CALL METHOD lo_http_client->close.

Here is the output:

4 REPLIES 4

MateuszAdamus
Active Contributor

0 Kudos
220

Hi Mateusz,

Thank you very much. I'm trying the solution you've provided, and I'm still testing it.

kartikrajag
Participant
0 Kudos
220

0 Kudos
220

Hi Kartik,

Thank you very much. I'm trying the solution you've provided, and I'm still testing it.