【问题标题】:Grape API is removing '+' from string (replacing with blank space)Grape API 正在从字符串中删除“+”(替换为空格)
【发布时间】:2019-04-04 09:53:01
【问题描述】:

我有一个葡萄 API,作为 POST 请求的一部分,我传递了一个包含“+”的字符串(它是一个电话号码)。 Grape 似乎正在删除 + 并将其替换为空格。

module V1
  class CustomerDetails < Grape::API
    before do
      error!("Unauthorized", 401) unless authenticated?
    end

    resource :customer_details do

      desc 'Update customer number'
      post anchor: false do
        params do
          requires :customer_id, type: String
          requires :customer_number, type: String
        end

        # Current behaviour: 
        # params[:customer_number] here will be ' 441920765847'

        # Expected behaviour: 
        # params[:customer_number] here will be '+441920765847'

      end
    end
  end
end

我希望使用邮递员发出 http POST 请求,参数 customer_number 的值为 +441920765847,并且它不会丢失 +(即不显示为 441920765847

【问题讨论】:

    标签: grape-api


    【解决方案1】:

    解决了!这是邮递员删除它,因为我是在参数(网址字符串)中发送它而不是在正文中

    【讨论】:

      猜你喜欢
      • 2011-04-15
      • 1970-01-01
      • 2011-09-21
      • 2017-11-20
      • 1970-01-01
      相关资源
      最近更新 更多