【问题标题】:How to pass null as values to any variable in cURL command or Browser command for REST ATG?如何将 null 作为值传递给 cURL 命令或 REST ATG 的浏览器命令中的任何变量?
【发布时间】:2016-04-07 09:34:26
【问题描述】:

第一次通话:

curl -L -v \
     -c customer_cookies.txt \
     -b customer_cookies.txt \
     -H "Content-Type: application/json" \
     -d "{\"couponClaimCode\":\"0001\"}" \
"http://localhost:7103/rest/model/atg/commerce/promotion/CouponActor/claimCoupon"

第二次通话:

http://localhost:7103/rest/model/atg/commerce/promotion/CouponActor/claimCoupon?couponClaimCode=0001

两个电话都在做同样的事情:传递优惠券代码。假设如果我想将 null 作为值传递,那么我应该怎么做呢?

【问题讨论】:

    标签: rest curl atg


    【解决方案1】:

    JSON 支持null。这个

    {"couponClaimCode": null}
    

    是有效的 JSON。如果接受 POST 的代码正确处理 JSON,这应该可以工作。

    传递一个空值couponClaimCode 作为查询参数取决于你的后端理解什么。会

    ?couponClaimCode=
    

    被解释为空字符串"" 还是null?怎么样

    ?couponClaimCode=null
    

    这是字符串"null" 还是null?您必须查看您的后端代码才能找到答案。

    【讨论】:

    • 当我使用 {"couponClaimCode": null} 时,我得到以下响应 {"formError":true,"formExceptions":[{"localizedMessage":"No coupon could be found for the claim代码。","errorCode":"noCouponFound"}]}。
    • 正如我所说:您必须了解您的后端。我帮不了你。
    【解决方案2】:

    这对我有用

    卷曲 -L -v -c customer_cookies.txt -b customer_cookies.txt -H“内容类型:应用程序/json” -d "{\"couponClaimCode\":\"\"}" "http://localhost:7103/rest/model/atg/commerce/promotion/CouponActor/claimCoupon"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-13
      • 1970-01-01
      • 2023-02-21
      • 2012-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多