相关疑难解决方法(0)

$ http.post()方法正在发送GET

注意:

我发现了一个可能相关的问题,需要在这里提出一个新问题


这是一个奇怪的问题.我在2年的时间里一直使用角度,从来没有遇到过这个问题.

我正在使用angular v1.5.0.我正在发布这样的帖子请求:

$http({
    method: "POST",
    url: "/myurl",
    data: {
        file: myFile // This is just an object
    }
});
Run Code Online (Sandbox Code Playgroud)

普通的POST请求对吗?得到这个.我查看控制台,"网络"选项卡将请求记录为GET.离奇.所以我已经开始像这样工作:

$http.post("/myurl", {file: myFile});
Run Code Online (Sandbox Code Playgroud)

一样.单步执行$http服务代码后,我确信正在正确设置标头.有没有其他人遇到这个问题?

更新

考虑到德国人的建议,我尝试使用该$resource服务:

promise = $resource("/upload").save()
Run Code Online (Sandbox Code Playgroud)

(由于其他原因,这会返回错误,它仍然可以正确执行POST).我遇到了同样的问题:请求在控制台中记录为GET.

以下是请求到达我的服务器时的标头:

GET /myurl/ HTTP/1.1
Host: localhost:8001
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cache-Control: no-cache
Connection: keep-alive
Pragma: no-cache
Referer: http://localhost:8001/myurl/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Run Code Online (Sandbox Code Playgroud)

更新2 …

http go angularjs angular-http

10
推荐指数
1
解决办法
5065
查看次数

Golang "301 Moved Permanently" if request path contains additional slash

I have been using golang's default http.ServeMux for http route handling.

wrap := func(h func(t *MyStruct, w http.ResponseWriter, r *http.Request)) func(http.ResponseWriter, *http.Request) {
    return func(w http.ResponseWriter, r *http.Request) {
        h(t, w, r)
    }
}

// Register handlers with default mux
httpMux := http.NewServeMux()
httpMux.HandleFunc("/", wrap(payloadHandler))
Run Code Online (Sandbox Code Playgroud)

Assume this server is accessible via http://example.com/

Very few of my client's requests were of path http://example.com/api//module (note the extra slash) which is redirected as 301 Moved Permanently. Exploring inside golang's http ServeMux.Handler(r *Request) …

redirect http go http-status-code-301

4
推荐指数
1
解决办法
4220
查看次数

golang http.FileServer() 中列出错误链接的目录

http.FileServer在 Go 中使用将一些静态文件提供到目录中。

这是我使用 mux 作为路由器来映射它的方式:

r.PathPrefix("/download").Handler(http.StripPrefix("/download", http.FileServer(http.Dir(dirPath)))).Methods("GET")
Run Code Online (Sandbox Code Playgroud)

其中dirPath是我的文件系统中目录的绝对路径。

现在,当使用 localhost:8080/download 询问目录列表时,它似乎工作正常,因为它返回这样的页面

<pre>
<a href="a.xml">a.xml</a>
<a href="b.xml">b.zip</a>
</pre>
Run Code Online (Sandbox Code Playgroud)

不幸的是,这些链接已损坏,因为我希望将它们映射到例如localhost:8080/download/a.xml,而文件服务器将它们映射到localhost:8080/a.xml

如何使我的目录列表/download在链接中保留路径前缀?

url http fileserver go

3
推荐指数
1
解决办法
2103
查看次数