英文:
Shopify add items to cart using get request working on browser but not working with a golang script
问题
我想要自动化在Shopify商店上添加商品到购物车的过程。例如,在http://www.oneness287.com
上。如果你想购买这些尺码为7.5的商品,访问http://oneness287-2.myshopify.com/cart/29741797961:1
会自动将商品添加到我的购物车并重定向到结账页面。
但是,当我在我的Golang代码中执行以下操作:
http.Get("http://oneness287-2.myshopify.com/cart/29741797961:1")
然后检查我的购物车时,购物车仍然是空的。这种情况有什么不同?在第一种情况下,我是从浏览器发出请求,而在第二种情况下,是我的脚本发出请求。我该如何修复这个问题?
英文:
I wanted to automate the process of adding items to cart on shopify stores. For example, at http://www.oneness287.com
. If you wish to buy these size 7.5 , going to http://oneness287-2.myshopify.com/cart/29741797961:1
automatically adds the product to my cart and redirects me to the checkout page.
But when I do
http.Get("http://oneness287-2.myshopify.com/cart/29741797961:1")
from my golang code, and then check my cart. The cart is still empty. What is different in this case? In the first case I am making the request from the browser, in the second my script is making the request. How do I fix it?
答案1
得分: 2
当您从Go代码发出请求时,服务器会创建一个新的会话(基本上是新的cookie),而浏览器请求有自己的会话,因此请求不会在同一个购物车上操作。如果您真的想要这样做,那么在Go代码中,您将需要发送浏览器中针对此特定域的所有cookie。
英文:
When you make the request from go code the server creates a new session (basically new cookie) whereas the browser request have its own session, hence the request are not operating on the same cart. If you really want to do this then in the go code you will have to send all the cookies that you have in browser for this particular domain.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论