首页 > 解决方案 > Grape API 正在从字符串中删除“+”(替换为空格)

问题描述

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

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

解决方案


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


推荐阅读