Building POST Request and Return JSON Data

与世无争的帅哥 提交于 2019-12-12 01:49:38

问题


I am having trouble building a POST request that should accept a CSV of a persons phone numbers ie. phoneNum1,phoneNum2,phoneNum3...phoneNum350

and then return a JSON object of those phone numbers that matched already in the database. I am testing with the chrome extension POSTMAN as such:

yet it returns ERROR 404 upon execution.

How can I reformulate this request to work?

the action:

def getActivatedFriends
    @results = BusinessUser.find_by_sql("SELECT 
                                            a.id
                                         ,  a.username
                                         ,  a.phoneNumber
                                         FROM sers a
                                         WHERE phoneNumber in (" + params[:friends_phone_number_csv].to_s + ") and
                                               removed = 0 and
                                               is_user = 1;")

    respond_to do |format|
        format.html
        format.json { render json: { friends_match: @results }}
    end         
end

the route:

  match '/getActivatedFriends/:friends_phone_number_csv',
  to: 'requests#getActivatedFriends', via: 'post',
  constraints: { friends_phone_number_csv: /([0-9]+,?)+/ } 

回答1:


The problem is with your route:

/getActivatedFriends/:friends_phone_number_csv

Should be:

/getActivatedFriends

The :friends_phone_number_csv implies that you are passing a URL parameter.



来源:https://stackoverflow.com/questions/29332019/building-post-request-and-return-json-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!