http/cookiejar - not sure why this isn't working

xuanbao · · 779 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p><a href="http://play.golang.org/p/wm0sQbmklO" rel="nofollow">http://play.golang.org/p/wm0sQbmklO</a></p> <p>Cookies are there but no way to access them?</p> <p>Also, when you do your own request (req := http.NewRequest), is the cookiejar used in your request? It looks like it&#39;s not and I must do req.AddCookie. I&#39;m not sure because right now nothing&#39;s working.</p> <p>edit : temporary(?) fix for my program : I req.AddCookie each cookie that comes from another function, without touching the jar, it works as expected.</p> <hr/>**评论:**<br/><br/>nuunien: <pre><p>For cookies to be automatically stored and accessed, you need to set the <code>Jar</code> field of the <code>http.Client</code> type with a CookieJar.</p></pre>Simpfally: <pre><p>It was done, thanks.</p> <p>I was just wondering why I couldn&#39;t access those cookies myself.</p></pre>willglynn: <pre><p>You <em>can</em> access the cookies yourself… in ways compliant with <a href="http://tools.ietf.org/html/rfc6265" rel="nofollow">the cookie specification</a>.</p> <p>Your <code>http.Cookie</code> is specified as <code>Secure</code>. <code>net.http.cookiejar.Jar</code> will therefore not return that cookie if you ask it about an <code>http://</code> URL, even with a matching domain.</p> <p>Changing the test URL to HTTPS causes the cookie to be returned:</p> <p><a href="http://play.golang.org/p/T0fa89yN-K" rel="nofollow">http://play.golang.org/p/T0fa89yN-K</a></p></pre>Simpfally: <pre><p>So that&#39;s why.. Thanks!</p> <p>I tried to find what each attributes really do but I couldn&#39;t find anything</p></pre>

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

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