I am trying to call a SOAP API over HTTP and I need advices. The problem is that when I set the property to say the content type should be "text/xml" it is not setting it:
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());
When I print out con.getContentType it prints out:
text/html; charset=UTF-8
How can I set it to text/xml charset=utf-8?
con.getContentType
returns the value of the Content-Type header field of URL resource , while setRequestProperty("Accept")
changes the property of the Accept header of the request .
Try getRequestProperty
to get the Accept header of the request:
System.out.println(con.getRequestProperty("Accept"));
To set and print the Content-Type
header of the request:
con.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
System.out.println(con.getRequestProperty("Content-Type"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.