Cookies do not work

xuanbao · · 426 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I tried posting to the IRC channel but it was a dead. I&#39;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&#39;s cookie database), however reading the cookie from Go does not work.</p> <p>The docs don&#39;t help at all. There&#39;s pretty much no examples of this in the wild. If you&#39;re too lazy to try it, the error returned is &#34;named cookie not present&#34;</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 = &#34;/&#34;</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&#39;m not sure. </p></pre>jrwren: <pre><p>This is the correct answer.</p> <p>Chrome-&gt;Developer Tools-&gt;Application-&gt;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&#39;re too lazy to try it, the error returned is &#34;named cookie not present&#34;.</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&#39;s passing them around through his browser, he doesn&#39;t need an additional cookie jar.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

426 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传