<p>I tried posting to the IRC channel but it was a dead. I'm trying a very simple cookie setup: <a href="http://pastebin.com/xd20FLHV" rel="nofollow">http://pastebin.com/xd20FLHV</a></p>
<p>The cookie is set properly (key/value in Chrome's cookie database), however reading the cookie from Go does not work.</p>
<p>The docs don't help at all. There's pretty much no examples of this in the wild. If you're too lazy to try it, the error returned is "named cookie not present"</p>
<p>Using go 1.7.4 on Windows, if it matters.</p>
<hr/>**评论:**<br/><br/>thesilentwitness: <pre><p>It seems to work if you do <code>c.Path = "/"</code>, but according to the docs this is optional, so I have no idea why you have to do this... Is Go setting Path automatically to your subpath and not / for your cookie perhaps? I'm not sure. </p></pre>jrwren: <pre><p>This is the correct answer.</p>
<p>Chrome->Developer Tools->Application->Cookies shows the path set as /cookie</p>
<p>The header transfered is:</p>
<p>Set-Cookie:TEST=TEST VALUE; Expires=Wed, 27 Dec 2017 14:12:13 GMT</p>
<p>Without an explicit path, the browser uses the current path from the URL.</p></pre>minderaser: <pre><p>I think you are 100% correct. In any event, setting path to / makes it work just fine. Even from other subpaths like localhost/apple with a different handler func the cookie still shows.</p>
<p>Thanks a bunch.</p></pre>hipone: <pre><blockquote>
<p>I tried posting to the IRC channel but it was a dead.</p>
</blockquote>
<p>Try <a href="https://invite.slack.golangbridge.org/" rel="nofollow">https://invite.slack.golangbridge.org/</a>.</p>
<blockquote>
<p>If you're too lazy to try it, the error returned is "named cookie not present".</p>
</blockquote>
<p>You need to configure (http.Client).Jar field before issuing requests (e.g. to the result of cookiejar.New()), the default http client does not pass cookies around. </p></pre>thesilentwitness: <pre><p>He's passing them around through his browser, he doesn't need an additional cookie jar.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传