首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在台风中表示来自curl的用户标志(-u)的内容?

如何在台风中表示来自curl的用户标志(-u)的内容?
EN

Stack Overflow用户
提问于 2013-08-09 06:50:56
回答 1查看 251关注 0票数 0

我想把卷发请求翻译成台风请求。卷曲请求:

代码语言:javascript
复制
@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}"}'}

台风请求:

代码语言:javascript
复制
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}"}')

当我运行台风请求,我得到一个回应说unauthorized,我相信这表明我的用户信息是不正确的。如何在台风请求中设置等效的-u标志?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-09 07:52:57

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

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

代码语言:javascript
复制
url = "http://httpbin.org/basic-auth/john/pwd1234"
Typhoeus::Request.new(url, userpwd: "john:pwd1234").run
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18141452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档