Content type for HTML fragments

In regards to XML/HTML document fragments, other than the xml-fragment referenced in the comments (now labeled as “no longer maintained”), there don’t appear to be any explicit, official references to document fragments and the content type header. However, some points to consider: The xml-fragment spec treats full documents and fragments the same in regards to …

Read more

How to set the Content-Type header for an HttpClient request?

The content type is a header of the content, not of the request, which is why this is failing. AddWithoutValidation as suggested by Robert Levy may work, but you can also set the content type when creating the request content itself (note that the code snippet adds application/json in two places-for Accept and Content-Type headers): …

Read more

Set Content-Type to application/json in jsp file

You can do via Page directive. For example: <%@ page language=”java” contentType=”application/json; charset=UTF-8″ pageEncoding=”UTF-8″%> contentType=”mimeType [ ;charset=characterSet ]” | “text/html;charset=ISO-8859-1” The MIME type and character encoding the JSP file uses for the response it sends to the client. You can use any MIME type or character set that are valid for the JSP container. The …

Read more

How to set http.ResponseWriter Content-Type header globally for all API endpoints?

You can define middleware for mux router, here is an example: func main() { port := “:3000” var router = mux.NewRouter() router.Use(commonMiddleware) router.HandleFunc(“/m/{msg}”, handleMessage).Methods(“GET”) router.HandleFunc(“/n/{num}”, handleNumber).Methods(“GET”) // rest of code goes here } func commonMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Add(“Content-Type”, “application/json”) next.ServeHTTP(w, r) }) } Read more in the documentation

Setting request header content-type to json in Spring Framework resttemplate [duplicate]

you can try using any method from below code 1 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(postBodyJson ,headers); restTemplate.put(uRL, entity); 2 RequestEntity<String> requestEntity = RequestEntity .post(new URL(attributeLookupUrl).toURI()) .contentType(MediaType.APPLICATION_JSON) .body(postBodyJson); restTemplate.exchange(requestEntity, responseClass); 3 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // if you need to pass form parameters in request with headers. MultiValueMap<String, …

Read more