![](/img/trans.png)
[英]Error while reindexing on Solr - RSolr::Error::Http: RSolr::Error::Http - 400 Bad Request - undefined field type
[英]Error while doing HTTP Request
我正在使用Typhoeus gem在我的rails應用程序中執行HTTP請求。 請求如下。
data = {"auth_token"=>"abcd" ,"employee" => {"method" => "add_employee"}}
header = { "Content-Type" => "application/json","Accept"=>"application/json"}
request = Typhoeus::Request.post("www.example.com",:body=> data.to_json,:headers => header)
在執行此操作時,auth_token已轉換為auth%5Ftoken = abcd。 實際上,我的API需要參數auth_token。 由於該API不允許訪問它。 引發未經授權的錯誤。 請幫我解決這個問題。 提前致謝。
我使用to_query更正了該問題。 實際上to_query正在將實際數據解析到API
這是一個使用RestClient的示例,該示例顯示了正確的數據提交,我希望Typhoeus不會有所不同:
data = {"auth_token"=>"abcd" ,"employee" => {"method" => "add_employee"}}
header = { "Content-Type" => "application/json","Accept"=>"application/json"}
RestClient.post("www.example.com", data.to_json, header){ |response, request, result|
puts "PAYLOAD:"+request.args[:payload]
}
這是預期的有效負載:
PAYLOAD: "{\"auth_token\":\"abcd\",\"employee\":{\"method\":\"add_employee\"}}"
使用傷寒:
data = {"auth_token"=>"abcd" ,"employee" => {"method" => "add_employee"}}
header = { "Content-Type" => "application/json","Accept"=>"application/json"}
request = Typhoeus::Request.post("www.example.com",:body=> data.to_json,:headers => header)
request.request.original_options[:body]
如預期的那樣,這是請求的有效負載。 所以你的代碼很好!
"{\"auth_token\":\"abcd\",\"employee\":{\"method\":\"add_employee\"}}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.