This commit is contained in:
Kevin Wan
2022-04-28 11:25:26 +08:00
committed by GitHub
parent cc09ab2aba
commit cef83efd4e
5 changed files with 9 additions and 6 deletions

View File

@@ -10,7 +10,10 @@ import (
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
) )
const httpTimeout = time.Second * 5 const (
httpTimeout = time.Second * 5
jsonContentType = "application/json; charset=utf-8"
)
// ErrWriteFailed is an error that indicates failed to submit a StatReport. // ErrWriteFailed is an error that indicates failed to submit a StatReport.
var ErrWriteFailed = errors.New("submit failed") var ErrWriteFailed = errors.New("submit failed")
@@ -36,7 +39,7 @@ func (rw *RemoteWriter) Write(report *StatReport) error {
client := &http.Client{ client := &http.Client{
Timeout: httpTimeout, Timeout: httpTimeout,
} }
resp, err := client.Post(rw.endpoint, "application/json", bytes.NewBuffer(bs)) resp, err := client.Post(rw.endpoint, jsonContentType, bytes.NewBuffer(bs))
if err != nil { if err != nil {
return err return err
} }

View File

@@ -10,7 +10,7 @@ const (
slash = "/" slash = "/"
colon = ':' colon = ':'
contentType = "Content-Type" contentType = "Content-Type"
applicationJson = "application/json" applicationJson = "application/json; charset=utf-8"
) )
// ErrGetWithBody indicates that GET request with body. // ErrGetWithBody indicates that GET request with body.

View File

@@ -2,7 +2,7 @@ package httpx
const ( const (
// ApplicationJson means application/json. // ApplicationJson means application/json.
ApplicationJson = "application/json" ApplicationJson = "application/json; charset=utf-8"
// ContentEncoding means Content-Encoding. // ContentEncoding means Content-Encoding.
ContentEncoding = "Content-Encoding" ContentEncoding = "Content-Encoding"
// ContentSecurity means X-Content-Security. // ContentSecurity means X-Content-Security.

View File

@@ -58,7 +58,7 @@ Future _apiRequest(String method, String path, dynamic data,
r = await client.getUrl(Uri.parse('https://' + serverHost + path)); r = await client.getUrl(Uri.parse('https://' + serverHost + path));
} }
r.headers.set('Content-Type', 'application/json'); r.headers.set('Content-Type', 'application/json; charset=utf-8');
if (tokens != null) { if (tokens != null) {
r.headers.set('Authorization', tokens.accessToken); r.headers.set('Authorization', tokens.accessToken);
} }

View File

@@ -25,7 +25,7 @@ suspend fun apiRequest(
requestMethod = method requestMethod = method
doInput = true doInput = true
if (method == "POST" || method == "PUT" || method == "PATCH") { if (method == "POST" || method == "PUT" || method == "PATCH") {
setRequestProperty("Content-Type", "application/json") setRequestProperty("Content-Type", "application/json; charset=utf-8")
doOutput = true doOutput = true
val data = when (body) { val data = when (body) {
is String -> { is String -> {