通过 Net::HTTP POST 时如何控制编码?
我正在尝试使用 ruby 为 Issuu 创建 API 包装器,但在尝试 POST 数据时遇到错误。当使用查询字符串中的所有参数通过浏览器尝试简单的 GET 时,我能够检索预期的结果;但是,当我尝试在代码中使用 POST 执行相同的操作(API 声称支持)时,我始终收到一条错误,指出我的 api 密钥的格式无效(他们的文档声明可能是编码问题)。
不管怎样,如果我想将我的值发布到特定的 URL,我将如何确保所有内容都以 UTF-8 编码?这是请求标头的一部分吗?或者在发布请求之前我是否需要先对我的字符串执行一些特定的操作?
I'm trying to create an API wrapper for Issuu using ruby and am running into errors when attempting to POST the data. When trying a simple GET through the browser with all the params in the querystring, I am able to retrieve the expected results; however, when I try to perform the same operation using a POST in code (which the API claims to support), I consistently get an error stating that my api key is in an Invalid Format
(which their documentation claims is likely an encoding issue).
Anyway, if I want to make POST my values to a specific URL, how would I go about ensuring that everything is encoded in UTF-8? Is this part of the request header? Or do I need to do something specific to my strings first before POSTing the request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑在表单定义中同时使用 enctype 和 accept-charset 属性。更多信息请访问:http://www.w3。 org/TR/html401/interact/forms.html#h-17.3
Consider using both the enctype and accept-charset attributes in your form definition. More information is available here: http://www.w3.org/TR/html401/interact/forms.html#h-17.3