You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter/Dart前端与Go后端POST请求问题及Cookie存储疑问

Hey there! Let's break down your two issues one by one to get you sorted out.

Cookie保存格式问题

Since your Go backend specifically checks for a Cookie named session, you need to make sure when you send subsequent GET requests, the request header includes the full key-value pair in the correct Cookie format. Here's what to do:

  • When you receive the Set-Cookie header from the backend (it’ll look something like session=your-uuid-here; Path=/; HttpOnly), you can either:
    1. Save the entire session=your-uuid-here string directly. Then, when making GET requests, add a header like Cookie: [saved-string] to your request.
    2. Save the key (session) and value (your-uuid-here) separately. When sending the request, construct the header value as session=your-uuid-here and add it to the Cookie header.
      Either way works, but the critical part is that the backend sees a Cookie named session with the correct UUID value. Don’t just save the UUID alone—without the session= prefix, the backend won’t recognize it as the right Cookie.
浏览器访问的EOF错误问题

Your guess about missing JSON data is spot-on! Here’s why this happens:

  • When you visit localhost:8080 directly in a browser, it sends a GET request with no request body. But your login endpoint probably expects a POST request with a JSON payload (like {"username":"your-username","password":"your-password"}).
  • Go’s JSON parser throws an EOF error when it tries to read a request body that doesn’t exist.

To fix this:

  • Use a tool like Postman or curl to send a proper POST request to your login endpoint. Make sure to set the Content-Type header to application/json and include the required JSON body with your login credentials.
  • If you want the browser to handle it, you’ll need to create a simple HTML form that sends a POST request with JSON data (or adjust your Go backend to accept GET requests for the login endpoint, though that’s not recommended for security reasons).

内容的提问来源于stack exchange,提问作者DanT29

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:13:35