What does "setRequestProperty("Accept", "application/json")" mean?

Koki
Tera Contributor

What does the following mean, which is code for calling ServiceNow's REST API?
Why is it necessary?
What is the difference between them?

"  setRequestProperty("Accept", "application/json");  "
"  setRequestProperty("Content-Type", "application/json");  "

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Koki,

Explained in the following IBM page.

https://www.ibm.com/docs/en/order-management?topic=services-specifying-http-headers

Other headers settings are explained in the following page in Japanese. These are standard http headers and not proprietary ServiceNow.

http://itdoc.hitachi.co.jp/manuals/3021/3021904200/PCAP0018.HTM

View solution in original post

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

setRequestProperty("Accept", "application/json") // The format of response we want to get from the server httpURLConnection.

 

setRequestProperty("Content-Type", "application/json");  "//Set the “content-type” request header to “application/json” to send the request content in JSON form.

Regards
Harish

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Koki,

Explained in the following IBM page.

https://www.ibm.com/docs/en/order-management?topic=services-specifying-http-headers

Other headers settings are explained in the following page in Japanese. These are standard http headers and not proprietary ServiceNow.

http://itdoc.hitachi.co.jp/manuals/3021/3021904200/PCAP0018.HTM

Thank you very much.

Many of the sample codes I found on the net did not specifically mention "Accept", so I thought it was only written for ServiceNow's REST API.

I am glad to have found a site that explains it clearly.