gojenkins icon indicating copy to clipboard operation
gojenkins copied to clipboard

UpdateConfig displays garbled characters when using Chinese

Open nxk88998 opened this issue 1 year ago • 3 comments

	config = fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<flow-definition plugin="[email protected]">
 <description></description>
 <keepDependencies>false</keepDependencies>
 <properties/>
 <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="[email protected]">
    <script>
测试
</script>
    <sandbox>true</sandbox>
 </definition>
 <triggers/>
 <disabled>false</disabled>
</flow-definition>`)


	 job.UpdateConfig(ctx, config)

测试 >> Jenkins displays garbled code >> 测è¯

nxk88998 avatar Feb 20 '24 11:02 nxk88998

已修复,添加charset=utf-8到Content-Type标头显式指定字符编码修复 func (r *Requester) PostXML(ctx context.Context, endpoint string, xml string, responseStruct interface{}, querystring map[string]string) (*http.Response, error) { payload := bytes.NewBuffer([]byte(xml)) ar := NewAPIRequest("POST", endpoint, payload) if err := r.SetCrumb(ctx, ar); err != nil { return nil, err } ar.SetHeader("Content-Type", "application/xml; charset=utf-8") ar.Suffix = "" return r.Do(ctx, ar, &responseStruct, querystring) }

nxk88998 avatar Feb 21 '24 01:02 nxk88998

如何解决的

ylighgh avatar May 11 '24 15:05 ylighgh

如何解决的

request.go文件中修改PostXML函数添加默认charset=utf-8

完整代码 func (r *Requester) PostXML(ctx context.Context, endpoint string, xml string, responseStruct interface{}, querystring map[string]string) (*http.Response, error) { payload := bytes.NewBuffer([]byte(xml)) ar := NewAPIRequest("POST", endpoint, payload) if err := r.SetCrumb(ctx, ar); err != nil { return nil, err } ar.SetHeader("Content-Type", "application/xml; charset=utf-8") ar.Suffix = "" return r.Do(ctx, ar, &responseStruct, querystring) }

nxk88998 avatar Aug 02 '24 06:08 nxk88998