我的任务是将this javascript file重建为ruby,但我收到的回复对我来说没有意义(错误):
{"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\":\"testusername@host.com\",\"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
答案 0 :(得分:0)
好的,所以我发现问题,在分析了与javascript相同但用PHP编写的内容(link)后,我意识到我发布的数据不正确,我需要发送数据,而不是JSON但是当查询字符串(k = v&amp; k = v)改变时:
PDFKit.configure do |config|
config.wkhtmltopdf = '/path/to/wkhtmltopdf'
end
到
set_type_converter -> (payload) {payload.to_json}
导致set_type_converter -> (payload) {query_params(payload)}
为:
post_body
似乎已经解决了这个问题。