调用PATCH API方法返回400错误?

发布于 2025-01-11 03:52:57 字数 1390 浏览 0 评论 0原文

我试图在 ABAP 中调用 PATCH 方法 API,但我总是收到代码 400,并带有错误消息,内容类型不受支持,其所需的 application/json 已在代码中设置。

    cl_http_client=>create_by_url(
      EXPORTING
        url                = lv_url
      IMPORTING
        client             = lo_client
      EXCEPTIONS
        argument_not_found = 1
        plugin_not_active  = 2
        internal_error     = 3
        OTHERS             = 4 ).
  
*   Set request parameter (Authorization)
    lo_client->request->set_header_field(
      name  = mc_param_name_authorization
      value = mc_auth_type_bearer && | { mv_access_token }|
    ).


*   Set request parameter (apiKey)
    lo_client->request->set_header_field(
      name  = mc_param_name_apikey
      value = CONV string( ms_access_settings-api_key )
    ).


*   Set request parameter (realm)
    lo_client->request->set_header_field(
      name  = mc_param_name_realm
      value = get_realm( mc_api_call_approve )
    ).
    lo_client->request->set_method( 'PATCH' ).
    lo_client->request->set_content_type( 'application/json' ).
    lo_http_client->request->set_cdata( lv_body_json ).

    lo_client->send( ).

    lo_client->receive(
      EXCEPTIONS
        http_communication_failure = 1
        http_invalid_state         = 2
        http_processing_failed     = 3
        OTHERS                     = 4 ).

I'm trying to call a PATCH Method API within ABAP, but i am always getting code 400 back with error message that content type is not supported, its needed application/json which i am setting already in the code.

    cl_http_client=>create_by_url(
      EXPORTING
        url                = lv_url
      IMPORTING
        client             = lo_client
      EXCEPTIONS
        argument_not_found = 1
        plugin_not_active  = 2
        internal_error     = 3
        OTHERS             = 4 ).
  
*   Set request parameter (Authorization)
    lo_client->request->set_header_field(
      name  = mc_param_name_authorization
      value = mc_auth_type_bearer && | { mv_access_token }|
    ).


*   Set request parameter (apiKey)
    lo_client->request->set_header_field(
      name  = mc_param_name_apikey
      value = CONV string( ms_access_settings-api_key )
    ).


*   Set request parameter (realm)
    lo_client->request->set_header_field(
      name  = mc_param_name_realm
      value = get_realm( mc_api_call_approve )
    ).
    lo_client->request->set_method( 'PATCH' ).
    lo_client->request->set_content_type( 'application/json' ).
    lo_http_client->request->set_cdata( lv_body_json ).

    lo_client->send( ).

    lo_client->receive(
      EXCEPTIONS
        http_communication_failure = 1
        http_invalid_state         = 2
        http_processing_failed     = 3
        OTHERS                     = 4 ).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文