根据RFC 1738使用Go编码URL字符串。

huangapple go评论94阅读模式
英文:

Encoding a URL string according to RFC 1738 using Go

问题

我正在尝试通过我的Go应用程序向Twitter发送请求,Twitter的API要求根据RFC 1738对消费者密钥和密钥进行编码。是否有一个内置的Go函数可以做到这一点?从我在net/url包中看到的内容来看,Go默认使用RFC 3986,我没有看到任何在http://golang.org/pkg/net/url/上允许我转换为RFC 1738的函数。

提前说明一下,我知道RFC 3986是较新的并且取代了1738,但Twitter API明确要求使用RFC 1738,所以我想我应该尝试这样做,以避免可能因为某个特殊情况而出现问题。为了澄清,我指的是此页面上“发出仅应用程序请求”部分的第1部分:https://dev.twitter.com/docs/auth/application-only-auth

英文:

I'm trying to send a request to Twitter through my Go application, and Twitter's API requires that you encode the consumer key and secret according to RFC 1738. Is there a Go function built to do this? From what I see in the net/url package, Go uses RFC 3986 by default, and I don't see any functions on http://golang.org/pkg/net/url/ that would allow me to convert to RFC 1738.

As a heads-up, I know that RFC 3986 is newer and obsoletes 1738, but the Twitter API asks specifically for RFC 1738 so I figured I should try to do that to avoid possibly getting screwed over by a corner case. For clarification, I'm talking about part 1 of the "Issuing application-only requests" section on this page: https://dev.twitter.com/docs/auth/application-only-auth

答案1

得分: 1

RFC 3986 更新了RFC 1738。通过遵守RFC 3986,您可以符合RFC 1738的要求,从而达到Twitter的期望。

因此,net/url包应该完全满足您的需求。

英文:

RFC 3986 updates RFC 1738. You can comply with RFC 1738 by complying with RFC 3986, and therefore achieve what Twitter expects.

So the net/url package should fully meet your needs.

huangapple
  • 本文由 发表于 2014年5月21日 04:48:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/23769675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定