gpt4 book ai didi

java - Mime 类型设置不正确

转载 作者:行者123 更新时间:2023-12-02 10:25:27 24 4
gpt4 key购买 nike

我正在尝试通过 HTTP 调用 SOAP API,我需要建议。问题是,当我将属性设置为内容类型应为“text/xml”时,它没有设置它:

    URL url = new URL(SOAP_URI);

URLConnection con = url.openConnection();

con.setDoOutput(true);
con.setRequestProperty("Accept","text/xml charset=utf-8");
System.out.println(con.getContentType());

当我打印出 con.getContentType 时,它​​会打印出:

    text/html; charset=UTF-8

如何将其设置为text/xml charset=utf-8?

最佳答案

con.getContentType 返回 URL 资源Content-Type header 字段的值,而 setRequestProperty("Accept") 更改请求Accept header 的属性。

尝试 getRequestProperty 获取请求的 Accept header :

System.out.println(con.getRequestProperty("Accept"));

设置并打印请求的 Content-Type header :

con.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
System.out.println(con.getRequestProperty("Content-Type"));

关于java - Mime 类型设置不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53989241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com