diff --git a/net/gclient/gclient_request.go b/net/gclient/gclient_request.go index be63859a08a..8375f30cf63 100644 --- a/net/gclient/gclient_request.go +++ b/net/gclient/gclient_request.go @@ -10,6 +10,7 @@ import ( "bytes" "context" "io" + "mime" "mime/multipart" "net/http" "os" @@ -172,7 +173,12 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data .. allowFileUploading = true ) if len(data) > 0 { - switch c.header[httpHeaderContentType] { + mediaType, _, err := mime.ParseMediaType(c.header[httpHeaderContentType]) + if err != nil { + // Fallback: use the raw header value if parsing fails. + mediaType = c.header[httpHeaderContentType] + } + switch mediaType { case httpHeaderContentTypeJson: switch data[0].(type) { case string, []byte: @@ -206,7 +212,12 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data .. if method == http.MethodGet { var bodyBuffer *bytes.Buffer if params != "" { - switch c.header[httpHeaderContentType] { + mediaType, _, err := mime.ParseMediaType(c.header[httpHeaderContentType]) + if err != nil { + // Fallback: use the raw header value if parsing fails. + mediaType = c.header[httpHeaderContentType] + } + switch mediaType { case httpHeaderContentTypeJson, httpHeaderContentTypeXml: