ruby
  • curb
  • 2013-01-15 58 views 5 likes 
    5

    全請求字符串我打算髮送的請求如下所示:檢索使用Ruby捲曲

    c = Curl::Easy.http_post("https://example.com", json_string 
        ) do |curl| 
         curl.headers['Accept'] = 'application/json' 
         curl.headers['Content-Type'] = 'application/json' 
         curl.headers['Api-Version'] = '2.2' 
        end 
    

    我想日誌正在取得確切的http請求。有沒有辦法獲得實際的請求(基本路徑,查詢參數,頭文件和正文)?

    +0

    您是否嘗試過你的塊中設置'curl.verbose = TRUE'? – onions

    回答

    1

    on_debug handler幫過我。在您的例子,你可以嘗試:

    curl.on_debug do |type, data| 
        puts type, data 
    end 
    
    0

    可以到達型動物的方式解決:

    您的塊裏面可以放:

    c.url # return the url with queries 
    c.total_time # retrieve the total time for the prev transfer (name resolving, TCP,...) 
    c.header_str # return the response header 
    c.headers # return your call header 
    c.body_str # return the body of the response 
    

    curl.verbose = true # that prints a detailed output of the connection 
    

    或者外塊

    請記得在調用這些方法之前調用c.perform(如果尚未執行)。

    還有更多選項可以在這裏找到:http://curb.rubyforge.org/classes/Curl/Easy.html#M000001

    相關問題