0
我一直在負責重建this javascript file到Ruby,但我得到的是沒有意義的(對我)一個響應的錯誤是:API沒有響應預期
{"api_error_code"=>1, "message"=>"Parameter 'username_or_email' is required.", "code"=>"API_ERROR", "target"=>"<webapp.resources.user_session_resource.UserSessionResource object at 0xb8e2a90>", "http_status"=>400}
它不道理監守我確實供應username_or_email
參數,你可以在這裏看到,我提出請求之前做身體上的看跌期權:
{"source_url":"/login/","data":"{\"options\":{\"username_or_email\":\"[email protected]\",\"password\":\"testpassword\"},\"context\":{}}","module_path":"App()>LoginPage()>Login()>Button(class_name=primary, text=Log In, type=submit, size=large)"}
它也似乎並不無論我怎樣設置有效載荷,無論是通過做@curl.post_body = payload
或@curl.http_post(payload)
或@curl.http_post(url,payload)
它只是迴應相同的錯誤。順便提一下@curl
是Curl::Easy
的一個實例。
我已經匹配了json數據請求,因爲原來有這麼做是怎麼回事?
這裏的請求至今:
require_relative "curb_dsl"
require 'json'
module Pin
class Client
Login_URL = "https://www.pinterest.com/resource/UserSessionResource/create/"
Repin_URL = "https://www.pinterest.com/resource/RepinResource/create/"
include Curb_DSL
class << self
def login(username_or_email, password)
self.new do
set_uri Login_URL
header 'Accept', 'application/json, text/javascript, */*; q=0.01'
header 'Accept-Language', 'en-US,en;q=0.5'
header 'Cache-Control', 'no-cache'
header 'DNT','1'
header 'Host', 'www.pinterest.com'
header 'Origin', 'https://www.pinterest.com'
header 'Referer', 'https://www.pinterest.com/'
header 'User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
header 'X-APP-VERSION', '18733c1'
header 'X-CSRFToken', 'K4C0QUu35Eoq1xjajbMluw7hOKibpQSW'
header 'X-NEW-APP', '1'
header 'X-Pinterest-AppState', 'active'
header 'X-Requested-With', 'XMLHttpRequest'
set_cookies({ ":_auth" => '0',csrftoken: 'K4C0QUu35Eoq1xjajbMluw7hOKibpQSW'})
set_payload({
source_url: "/login/",
data: {
options: {
username_or_email: username_or_email,
password: password
},
context: {}
}.to_json,
module_path: "App()>LoginPage()>Login()>Button(class_name=primary, text=Log In, type=submit, size=large)"
})
set_type_converter -> (payload) {payload.to_json}
set_error_handler -> {
JSON.parse(body)['resource_response']['error'].to_s
}
puts post_body
post
@csrftoken = resp_cookies['csrftoken']
end
end
end
end
end
在你的控制器中放置一個斷點並檢查'params'的值。確保頂級密鑰在那裏。 –
嗯,什麼?什麼控制器? – Thermatix