HTTP Content-Type

HTTP HEADER FIELDS

Response Headers

Content-Type

For instance, if it’s an HTML page, it’ll have a content-type of text/html; css files would be text\css; images you have image\png``image\jpeg. If it’s json data it’ll be application/json

Request Headers

Content-Type

json data it’ll be application/json

在这里插入图片描述

Param

Path

在这里插入图片描述

result:

HTTP packet报文 ver.

GET /portal/62bec1591aeb41ad3f1a6503/62eb6ae76e1446cc1344c34b/check/MAU HTTP/1.1
Host: 127.0.0.1:8080rights
User-Agent: apifox/1.0.0 (https://www.apifox.cn)

cURL ver.

curl --location --request GET 'http://127.0.0.1:8080rights/portal/62bec1591aeb41ad3f1a6503/62eb6ae76e1446cc1344c34b/check/MAU' \
--header 'User-Agent: apifox/1.0.0 (https://www.apifox.cn)'

curl --location --request GET ‘http://127.0.0.1:8080rights/portal/62bec1591aeb41ad3f1a6503/62eb6ae76e1446cc1344c34b/check/MAU’ \ --header ‘User-Agent: apifox/1.0.0 (https://www.apifox.cn)’

corresponse to Spring @PathVariable

Query

I think… it’s seldom used in RESTful

HTTP packet ver.

GET /goods/portal/dau/accumulate?instanceNo=olj2l3rjl23jlr2&accountNo=falejflkafjlkeajlk2313 HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: apifox/1.0.0 (https://www.apifox.cn)

corresponse to Spring @RequestParam

ResponseEntity<DauAccumResp> dauAccumulateGet(@RequestParam(value = "instanceNo", required = false) String instanceNo, @RequestParam(value = "accountNo", required = false) String accountNo);

Forms can also send Querys – when they method=get .

Body - application/json

Raw data. Same as plain text.

在这里插入图片描述

HTTP packet ver.

POST /portal/getInstanceNoListMauInfo HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: apifox/1.0.0 (https://www.apifox.cn)
Content-Type: application/json
Content-Length: 118

{
    "accountNo": "5a597f35085a2000144a10ed",
    "instanceNoList": [
        "59f86b4832eb28071bdd9214"
    ]
}

cURL ver.

curl --location --request POST 'http://127.0.0.1:8080/goods/portal/getInstanceNoListMauInfo' \
--header 'User-Agent: apifox/1.0.0 (https://www.apifox.cn)' \
--header 'Content-Type: application/json' \
--header 'Content-Length: ' \
--data-raw '{
    "accountNo": "5a597f35085a2000144a10ed",
    "instanceNoList": [
        "59f86b4832eb28071bdd9214"
    ]
}'

Corresponse to Spring @RequestBody

ResponseEntity<instListMauResp> instanceNoListMauInfoPost(@RequestBody(required = false) InstListMauReq instListMauReq);

Without @RequestBody , you can’t read the value.

在这里插入图片描述


Body - multipart/form-data

表单

method 属性,它用于定义表单数据的提交方式,可以是以下值:

  • post:Method HTTP POST ,form data will be included in form body then be sent to server,it’s for submit sensitive data,like username and password。
  • get:Default,method HTTP GET ,form data will be attached on action 属性的 URL 中,并以 **?**作为分隔符,it’s for insensitive data,如分页等。例如:https://www.runoob.com/?page=1,这里的 page=1 就是 get 方法提交的数据。

The form-data option in Postman simulates filling out a form on a website. This can also be used for attaching files to the keys as well.

在这里插入图片描述


Back to our pmsBrand example,

HTTP packet ver.

POST /jsr303/pmsBrand/ HTTP/1.1
Host: localhost:8080
Content-Length: 402
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="name"

brandname1
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="sort"

1
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="logo"

logo1
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="description"

desc1
----WebKitFormBoundary7MA4YWxkTrZu0gW

上面估计少了 charset=utf-8. 总之不太准,凑合看吧。

Don’t use @RequestBody in java spring! You’ll be responsed by a json:

{
    "timestamp": "2023-02-05T12:44:40.532+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "path": "/jsr303/pmsBrand/"
}

warn log:

[org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘multipart/form-data;boundary=--------------------------759349441963430385117791;charset=UTF-8’ not supported]

Body - application/x-www-form

The URL-encoded data sends encoded data to the server, and uses the same encoding as that of the URL parameters. Postman will encode the desired data before sending it. Postman encodes both the key and the value.

HTTP packet ver.

POST /jsr303/pmsBrand/ HTTP/1.1
Host: localhost:8080
Content-Type: application/x-www-form-urlencoded
Content-Length: 44

name=brandname3&logo=logo3&description=desc3

上面估计少了 charset=utf-8, 同上, 不太准

Same thing, don’t use @ResquestBody in java spring.

warn log:

[org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported]

Difference BETWEEN

form-data, x-www-form-urlencoded and raw

Difference Between form-data, x-www-form-urlencoded and raw in Postman | Baeldung

We can use the different forms of data content types as defined by the W3C committee. They’ve defined multiple formats for sending the data over the Network Layer. These include form-data, x-www-form-urlencoded, and raw data. By default, we can send data in simple text/ASCII format by using the x-www-form-urlencoded format.

However, using the x-www-form-urlencoded data type has a data limit. As such, we can use form-data for sending large binary or non-ASCII text to the server.

The raw data type sends any plain text or JSON to the server, as the name suggests. It supports multiple content types, and Postman will send the raw data without any modifications

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值