0

我想将 curl 请求转换为 Typhoeus 请求。卷曲请求:

@response = %x{curl -i https://track.customer.io/api/v1/customers/#{@client.id} \
        -X PUT \
        -H "Content-Type: application/json" \
        -u #{APP_CONFIG[:customerio][:api_key]}:#{APP_CONFIG[:customerio][:api_key]} \
        -d '{
          "email":"#{@client.email}",
          "name":"#{@client.name}",
          "id":"#{@client.id}",
          "created_at":"#{@client.created_at.to_time.to_i}"}'}

台风要求:

request = Typhoeus::Request.new(
    "https://track.customer.io/api/v1/customers/4", 
    ssl_verifypeer: false,
    method: :put,
    headers: {
        "Content-Type" => "application/json",
        "user_agent" => "#{APP_CONFIG[:customerio][:api_key]}:#{APP_CONFIG[:customerio][:api_key]}"},
    body: '{
    "email":"first@last.com", 
    "name":"Name is here",
    "id":"4",
    "created_at":"#{Time.now}"}')

当我运行 Typhoeus 请求时,我收到一条响应,说unauthorized我相信这表明我的用户信息不正确。如何在 Typhoeus 请求中设置等效的 -u 标志?

4

1 回答 1

1

如何在 Typhoeus 请求中设置等效的 -u 标志?

使用userpwd选项哈希中的键,例如:

url = "http://httpbin.org/basic-auth/john/pwd1234"
Typhoeus::Request.new(url, userpwd: "john:pwd1234").run
于 2013-08-09T07:52:57.817 回答