doujun5009 2017-08-08 03:23
浏览 41
已采纳

使用Echo提供文件

I'm trying to serve multiple files with Echo, but it doesn't work every time. The api code looks like this:

package main

import (
    "github.com/labstack/echo"

    "net/http"
)

func main() {
    e := echo.New();

    e.GET("/", home);

    e.File("/data1", "assets/data1.csv");

    e.File("/data2", "assets/data2.csv");

    e.Logger.Fatal(e.Start(":4243"));
}

func home(c echo.Context) error {
  return c.String(http.StatusOK, "Are you lost?");
}

To be precise, it does work for the very first file fetching, but then keeps failing for any subsequent calls (be them file fetching or more "classic" calls). The error message is a tad different for each browser:

In Chrome:

SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Bearer {the_entire_content_of_the_first_fetched_file}' is not a valid HTTP header field value.

In Firefox:

SyntaxError: An invalid or illegal string was specified

In Edge, simply:

SyntaxError

Tried activating CORS, nothing changed.

Looks to work pretty well with Postman. Maybe it's a problem with how I do fetch my data in my application?

If you need perhaps a bit more information, this thread is directly related to my previous one (Vuejs with axios request in vuex store: can't make more than one request, why?), but I didn't want to mix them up, as I don't know yet if I'm mistaken in my Vue code or my Echo one...

  • 写回答

3条回答 默认 最新

  • duan1982453 2017-08-08 06:51
    关注

    Welp, seems it was my application's fault all along! My Echo api seems fine... for now!

    If someone has the same problem, perhaps this Vuejs with axios request in vuex store: can't make more than one request, why? will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算