Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby API未按预期响应_Ruby_Curb - Fatal编程技术网

Ruby API未按预期响应

Ruby API未按预期响应,ruby,curb,Ruby,Curb,我的任务是重建到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>", "

我的任务是重建到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}
通过执行
@curl.post\u body=payload
@curl.http\u post(payload)
@curl.http\u 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
需要相对的“路缘dsl”
需要“json”
模块引脚
类客户端
登录\u URL=”https://www.pinterest.com/resource/UserSessionResource/create/"
Repin_URL=”https://www.pinterest.com/resource/RepinResource/create/"
包括路缘石DSL
类“0”,csrftoken:'K4C0QUu35Eoq1xjajbMluw7hOKibpQSW'})
设置有效载荷({
源url:“/login/”,
数据:{
选项:{
用户名或电子邮件:用户名或电子邮件,
密码:密码
},
上下文:{}
}。致,
模块路径:“应用程序()>登录页面()>登录()>按钮(类名称=主,文本=登录,类型=提交,大小=大)”
})
设置_type_converter->(有效载荷){payload.to_json}
设置错误处理程序->{
JSON.parse(body)['resource\u response']['error'].to
}
放在柱体上
邮递
@csrftoken=resp_cookies['csrftoken']
结束
结束
结束
结束
结束

好的,所以我发现了问题,在分析了与javascript相同但用PHP()编写的内容后,我意识到我发布的数据不正确,我需要发送数据,不是JSON,而是查询字符串(k=v&k=v)更改:

set_type_converter -> (payload) {payload.to_json}

这导致
post_body
为:

source_ury=%2Flogin%2F&data=%7B%22options%22%3A%7B%22username_or_email%22%3A%22testusername%40host.com%22%2C%22password%22%3A%22testpassword%22%7D%2C%22context%22%3A%7B%7D%7D&module_path=App%28%29%3ELoginPage%28%29%3ELogin%28%29%3EButton%28class_name%3Dprimary%2C+text%3DLog+In%2C+type%3Dsubmit%2C+size%3Dlarge%29

它似乎已经解决了问题。

在控制器中设置一个断点,并检查
参数的值。确保顶级钥匙在那里。嗯,什么?什么控制器?
set_type_converter -> (payload) {query_params(payload)}
source_ury=%2Flogin%2F&data=%7B%22options%22%3A%7B%22username_or_email%22%3A%22testusername%40host.com%22%2C%22password%22%3A%22testpassword%22%7D%2C%22context%22%3A%7B%7D%7D&module_path=App%28%29%3ELoginPage%28%29%3ELogin%28%29%3EButton%28class_name%3Dprimary%2C+text%3DLog+In%2C+type%3Dsubmit%2C+size%3Dlarge%29