나는 다음과 같은시나 코드가 :미스터리
post '/bucket' do
# determine if this call is coming from filling out web form
is_html = request.content_type.to_s.downcase.eql?('application/x-www-form-urlencoded')
# If this is a curl call, then get the params differently
unless is_html
params = JSON.parse(request.env["rack.input"].read)
end
p params[:name]
end
I이 사용 컬를 호출 할 경우, params
값을 가지고 있지만, 이것은 웹 양식을 통해 호출 될 때, 다음 params
이 nil
하고 params[:name]
는 아무 상관이 없다 . 나는 그것이 일어나는 이유를 알아 내고 다른 사람들의 도움을 구하는 데 몇 시간을 보냈지 만 아무도 실제로 무슨 일이 일어나고 있는지 알 수 없었다.
params = JSON.parse(request.env["rack.input"].read)
다음 params
은 "웹 형식"게시물에 대한 올바른 값을 가지고 :이 줄을 주석하는 경우주의해야 할
한 가지입니다.
사실, 목표는이 코드 CURL 호출에 의해 호출되는 경우 params
값을 얻을 수 있습니다, 그래서 사용 :
params = JSON.parse(request.env["rack.input"].read)
하지만 웹 형태의 게시물을 엉망. 누구든지이 신비를 풀 수 있습니까? 당신이 알고 당신이 그것을 볼 경우
if (params['webform'])
# this is a request from the form
else
# this is a request from Curl
end
:
이것은 Curl 대 웹 페이지 양식의 경우가 아니라 'application/x-www-form-urlencoded'대 'multipart/form-data'의 경우 일 수 있습니다. – L2G
Curl'POST' 요청과 폼을 사용하는 브라우저의 요청에 대한'content_type'은'application/x-www-form-urlencoded'입니다. –