Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateConfig displays garbled characters when using Chinese #320

Open
nxk88998 opened this issue Feb 20, 2024 · 3 comments
Open

UpdateConfig displays garbled characters when using Chinese #320

nxk88998 opened this issue Feb 20, 2024 · 3 comments

Comments

@nxk88998
Copy link

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


	 job.UpdateConfig(ctx, config)

测试 >> Jenkins displays garbled code >> æµ�è¯

@nxk88998
Copy link
Author

已修复,添加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) }

@ylighgh
Copy link

ylighgh commented May 11, 2024

如何解决的

@nxk88998
Copy link
Author

nxk88998 commented Aug 2, 2024

如何解决的

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) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants