如題
小小架了一個Nginx_uploasd_modul在後端,再寫一段golang程式想將圖片上傳至伺服器但一直跳出415 Unsupported Media,想請為各位大大,指點一下剛學golang不到一個禮拜的小小
package main
import (
"bufio"
//"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
file, err := os.Open("test1.jpg")
if err != nil {
fmt.Println(err)
}
defer file.Close()
a := bufio.NewReader(file)
//r := bytes.NewReader(*file)
resp, err := http.Post("http://35.237.210.90:80/upload", "1_name", a)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(body))
}
執行結果
c:/go/bin/go.exe run main.go
<html>
<head><title>415 Unsupported Media Type</title></head>
<body bgcolor="white">
<center><h1>415 Unsupported Media Type</h1></center>
<hr><center>nginx/1.10.2</center>
</body>
</html>
Success: process exited with code 0.