Skip to Content
-1

cl_http_client FOR 404 'the requested resource is not available'

hi,everyone,there is a very strange problem. i am make a connecttion with third system by fm cl_http_client(REST).The url need 3 parameter: useID、username、email,and i will sent an email after excuse successfully。

but now,there is a very very strange problem!!!some uername can sent email successfully,but others will return " 404 'the requested resource is not available' " like this,(there are not different just for username and not limit for username or others parameter!!! )

so,anyone konws what cause this?thanks advance!

success:

error:

CODE:

SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}

FORM GET_DATA_FROM_URL  USING    P_L_URL

                                 P_I_PERNR

                        CHANGING P_O_TYPE

                                 P_O_MESSAGE

                                 .



  DATA:http_client TYPE REF TO IF_HTTP_CLIENT,

       gv_cdata TYPE string.

  DATA: loc_conv    TYPE REF TO cl_abap_conv_in_ce,

        l_xstr      TYPE xstring,

        l_str       TYPE string,

        l_result    TYPE string.



  "return data

  DATA:L_CODE        TYPE C,"return code

       L_MESSAGE     TYPE STRING,

       L_DATA        TYPE STRING,

       L_SCORE       TYPE STRING,

       L_PASS        TYPE STRING,

       L_STRING_TEMP TYPE STRING,

       L_STRING_TEMP1 TYPE STRING

       .

  DATA:L_LENGTH TYPE I.

  DATA:L_LOOP_INDEX TYPE I,"loop deinx

       l_INDEX_TEMP TYPE I."index sum

  DATA:L_TABIX TYPE SY-TABIX.



  DATA:L_LINE_MESSAGE TYPE I,"index of MSG

       L_LINE_CODE TYPE I,"index of CODE

       L_LINE_PASS TYPE STRING,"index of PASS

       L_LINE_SCORE TYPE I."index of SCORE



  CALL METHOD cl_http_client=>create_by_url

    EXPORTING

      url                = P_L_URL

    IMPORTING

      client             = http_client

    EXCEPTIONS

      argument_not_found = 1

      plugin_not_active  = 2

      internal_error     = 3

      OTHERS             = 4.



** Set request method to GET or POST

  http_client->request->set_method( if_http_request=>co_request_method_post ).



*  CALL METHOD http_client->request->set_header_field

*    EXPORTING

*      name  = 'content'

*      value = 'test'.

*  CALL METHOD http_client->request->set_header_field

*    EXPORTING

*      name  = 'target'

*      value = '18961701938'.

*

*  CALL METHOD http_client->request->set_header_field

*    EXPORTING

*      name  = 'Content-Type'

**      value = 'application/json'. "

*      value = 'text/html;charset=utf-8'. "utf-8





  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_xstr = http_client->response->get_data( ).



  IF sy-subrc = 0 .

    http_client->close( ).

  ENDIF.



  CALL METHOD cl_abap_conv_in_ce=>create

    EXPORTING

      input       = l_xstr

      encoding    = 'UTF-8'

      replacement = '?'

      ignore_cerr = abap_true

    RECEIVING

      conv        = loc_conv.



  TRY.

      CALL METHOD loc_conv->read

        IMPORTING

          data = l_str.

    CATCH cx_sy_conversion_codepage.

    CATCH cx_sy_codepage_converter_init.

    CATCH cx_parameter_invalid_type.

    CATCH cx_parameter_invalid_range.

  ENDTRY.



  REPLACE ALL OCCURRENCES OF REGEX '\{*' IN l_str WITH SPACE .

  REPLACE ALL OCCURRENCES OF REGEX '\}*' IN l_str WITH '' .

  REPLACE ALL OCCURRENCES OF REGEX '\[*' IN l_str WITH '' .

  REPLACE ALL OCCURRENCES OF REGEX '\]*' IN l_str WITH '' .

  REPLACE ALL OCCURRENCES OF REGEX '\"*' IN l_str WITH '' .



  SPLIT l_str AT ',' into TABLE DATA(LT_RESULT_TEMP).



  DESCRIBE TABLE LT_RESULT_TEMP LINES DATA(L_LINE).

  L_LINE_CODE = 1.

  L_LINE_MESSAGE = 2.





  "code

  READ TABLE LT_RESULT_TEMP INTO DATA(LS_RESULT_TEMP) INDEX L_LINE_CODE.

  IF SY-SUBRC EQ 0.

    SPLIT LS_RESULT_TEMP AT ':' INTO L_STRING_TEMP  P_O_TYPE.

  ENDIF.



  "MESSAGE

  READ TABLE LT_RESULT_TEMP INTO LS_RESULT_TEMP INDEX L_LINE_MESSAGE.

  IF SY-SUBRC EQ 0.

    SPLIT LS_RESULT_TEMP AT ':' INTO L_STRING_TEMP  P_O_MESSAGE.

  ENDIF.





ENDFORM.
error.png (14.8 kB)
success.png (9.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Please reformat your code, there is CSS code in it + there is one blank line between every line. I see that you have a common issue with your web browser, so first paste the code to notepad, then copy it again and paste it in the web browser (or use directly the context menu "paste unformatted" if your browser has this option). Thank you.

  • PS: CL_ABAP_CODEPAGE is easier to work with, than CL_ABAP_CONV_IN_CE.

  • Get RSS Feed

1 Answer

  • Mar 05 at 07:56 AM
    -1

    I have found why!it is because of the encode!my system is HANA 1511 unicode.when i use cl_http_client=>create_by_url to connect the thrid system, the username is chinese,it make some different in unicode and non-unicode for chinese.so i get the error!

    Add comment
    10|10000 characters needed characters exceeded

    • If it doesn't answer the question the please don't use an answer to post such information. Use the comment section instead, just like Sandra did.

      I'm sure you'll find some information on other, non-SAP sites on how Unicode affects passing the user/password in HTTP connections.