草庐IT

http-error

全部标签

go - 为什么客户端通过 http.ServeContent 阅读我的视频时一直关闭连接?

我目前正在做一个小项目,通过http.ServeContent向浏览器或其他媒体客户端提供视频服务。我已经实现了自己的ReadSeeker,如下所示://theseekisnotfullyworkingyetbutworksfinefortheinitialtwocallsthatisbeingcalledinternallyfromhttptodecidethefilesize.func(c*Client)Seek(offsetint64,whenceint)(tint64,eerror){switchwhence{case0:t=offsetcase1:t=c.seek+offse

unit-testing - 如何测试/重构测试调用 http.ListenAndServe 的函数

我正在学习go并且正在开发一个简单的服务,该服务从队列中提取一些数据并将其保存在数据库中。它还运行一个网络服务器以允许抓取数据。现在我有两个go文件(为简洁起见省略了一些文本):funcmain(){parseConfig()s:=&Service{ServiceConfig:config}err:=s.Run()iferr!=nil{panic(err)}}然后是服务的定义(为简洁起见,再次省略了一些部分):func(s*Service)Run()error{iferr:=s.validate();err!=nil{returnerr}iferr:=s.initDB();err!=n

http - 我正在努力将 id 从 mysql 附加到 URL

我正在尝试向url附加一个id(和其他信息),以便稍后访问它,但经过一番研究后我找不到正确的方法。我试过使用Get()方法、query()、Add(),但无法重定向URL。varemail_ployerstringfuncRegisterNewPloyer(whttp.ResponseWriter,r*http.Request){ifr.URL.Path!="/ployer/register"{http.Error(w,"404notfound.",http.StatusNotFound)return}db:=connect.ConnectDB()deferdb.Close()swit

go - 如何在 Golang 中修复 ‘net/http set header ORIGIN’

我构建了一小段代码,具有从网站获取信息的功能,看起来它无法设置原点,因为在php中使用curl,我能够获得http状态为200的数据。然后我得到403。希望大家帮忙。非常感谢req,err:=http.NewRequest("GET","https://immortal.hydrax.net/0/BRlsM329RNjbSqlWnRF36A4Kf5jx6qlZmoeLnJRi9A6b",nil)iferr!=nil{log.Fatal(err)}req.Header.Set("User-Agent","Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleW

http - Golang的 "net/http"中客户端HTTP请求和服务端HTTP请求有什么区别

我看到有人使用“net/http”包的NewRequest()方法来测试API。为什么不使用“net/http/httptesting”中的NewRequest()方法?有什么不同?文档建议thefollowing://TogenerateaclientHTTPrequestinsteadofaserverrequest,see//theNewRequestfunctioninthenet/httppackage.例如,在处理cookie方面会有什么不同?两者看起来非常相似。 最佳答案 TL;DR:它们是相同的类型,在两个用例中的使

go - 为什么 "gofmt -d"给出 "computing diff: exec: "diff": executable file not found in %PATH%"error on windows?

我想看看我在golang文件中犯了哪些错误。为了弄清楚,我发出这样的命令:gofmt-dmyfile.go根据gofmt--help手册,它应该列出文件的当前版本和所需版本的差异。取而代之的是,它会生成此错误消息:computingdiff:exec:"diff":executablefilenotfoundin%PATH%如何解决这个问题? 最佳答案 gofmt工具假设系统已经安装了可用的diff。遗憾的是,此工具不是标准Windows安装的一部分,因此您需要手动添加它。对于我们大多数人来说,最简单的方法是添加我们计算机上已有的d

go - xorm 示例不工作 : "runtime error: invalid memory address or nil pointer dereference"

基于this示例我试图编写一个程序,该程序将从数据库返回一些数据。不幸的是,根据运行时控制台输出,(或多或少)相同的程序结构会在此处导致内存错误err:=orm.Find(&sensorDataEntry)。我在这里错过了什么?示例和我的程序都有使用make()创建的slice,并在Find()方法中使用引用。有问题的代码:packagemainimport("fmt""net/http""time""github.com/gorilla/mux"_"github.com/lib/pq"//"database/sql""github.com/go-xorm/xorm")varorm*x

go - HTTP : server gave HTTP response to HTTPS client

我正在使用go来使用googlemapsgeocodingAPI,但我不断收到此错误:TheHTTPrequestfailedwitherrorGethttps://maps.googleapis.com/maps/api/geocode/json?address=Bangalore&key=KEY:http:servergaveHTTPresponsetoHTTPSclient错误中的url在我的浏览器中工作正常并给出适当的响应,但不会在下面的代码片段中给出我想要的:packagemainimport("fmt""io/ioutil""net/http")funcmain(){key

docker - 从 Ubuntu amd64 到 arm7l : exec user process caused "exec format error" 进行交叉编译

从amd64到arm7l的交叉编译让我头疼我终于可以用GitlabCI做到这一点,所以现在,我在docker镜像中编译我的二进制文件,这是dockerfile:FROMgolangWORKDIR/go/src/gitlab.com/company/edge_to_bcCOPY..RUNdpkg--add-architecturearmhf&&aptupdate&&apt-getinstall-ygcc-arm-linux-gnueabihflibltdl-dev:armhf我将其构建为然后我将使用名称ubuntu:cross-compil构建新容器“cross-compil”现在,我可

Golang http 服务器根据内容类型返回 html 或 json

我正在尝试使用gorillamux在Golang中编写简单的RESTful应用程序。我写了几个如下所示的处理程序:funcgetUser(whttp.ResponseWriter,r*http.Request){ifr.Header.Get("Content-type")=="application/json"{w.Header().Set("Content-Type","application/json")u,err:=_getUser(r)iferr!=nil{http.NotFound(w,r)return}json.NewEncoder(w).Encode(u)//askedf