LoginSignup
35
24

More than 1 year has passed since last update.

[HTTPヘッダー]AcceptとContent-Typeについて

Last updated at Posted at 2020-08-03

Accept

クライアント側がどんなデータを処理できるかを表す。

curl -H "Accept: application/json" https://XXXX.com

Content-Type

実際にどんな形式のデータを送信したかを表す。

第一義的にはサーバ側がクライアント側へ返すレスポンス内で使われる。

ただ、クライアント側がサーバ側へPOSTPUTメソッドで何かしらのデータを渡す際にも使える。

POST /foo HTTP/1.1
Content-Length: 68137
Content-Type: text/html; charset=UTF-8

Content-Typeには色々値が入れられる。アプリ開発などでは以下を使用することが多い。

  • application/json

    • jsonフォーマットでデータが送受信される( {“email”:"xxxxx",”id”:"YYYY"}のような形)
  • application/x-www-form-urlencoded

    • エンコードされたurlでデータが送受信される(email=xxxxx&id=YYYYYのような文字列がエンコードされる)

参考

stack overflow - REST API - Use the “Accept: application/json” HTTP Header
MDN Web Docs - Content-Type
Content-typeについて少し勉強してみよう:application/jsonとapplication/x-www-form-urlencodedの違い

35
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
24