简体   繁体   English

在Net :: HTTP变量中展开单引号?

[英]Expand single quotes in a Net::HTTP variable?

I am using Net::HTTP to get a request from a Google API with a custom header: 我正在使用Net :: HTTP从具有自定义标头的Google API获取请求:

req = Net::HTTP::Get.new(uri.request_uri, {'Authorization' => 'GoogleLogin auth=#{auth}'})

The #{auth} is a variable that changes each time I run the program, so I made a variable with it, but the single quotes don't expand it. #{auth}是每次运行程序时都会更改的变量,因此我使用它创建了一个变量,但是单引号不会将其扩展。 I can't change the single quotes to double quotes, because Google only accepts the header with single quotes. 我无法将单引号更改为双引号,因为Google仅接受带单引号的标头。

Is there any way to expand the variable but keep the single quotes? 有什么方法可以扩展变量但保留单引号吗?

However, I can't change the single quotes to double quotes, because google only accepts the header with single quotes. 但是,我无法将单引号更改为双引号,因为google只接受带单引号的标头。

So hard to believe it. 很难相信。

Anyway, try Kernel%sprintf or its shorter version just str % [arguments..] . 无论如何,请尝试使用Kernel%sprintf或更短版本的str % [arguments..] It will help. 我会帮你的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM