http 协议 contentType transfer-encoding相关

本文探讨了HTTP头部字段Content-Type及Transfer-Encoding的作用与应用场景,特别是application/octet-stream和chunked编码方式的特点及其在POST和GET请求中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

application/octet-stream;这个是contenttype 表明是二进制文件(可执行文件吧),好像没有撒特殊意思,相当于没编码直接输出2进制数据(用在返回比较多);

transfer-encoding:chunked在单独post或者get(返回)的时候比较有用;

chunked 在multipart/XXX 的boundary里的content-transfer-encoding中貌似没什么意思,因为那个multipart的协议已经定义了数据段的边界,而且multipart/XXX的总content-length已经标明体长度。

public static void main(String[] args) throws Exception { StringBuilder builder = new StringBuilder(); builder.append("{\"productId\":"); builder.append("\""); builder.append(PRODUCT_ID); builder.append("\""); builder.append(","); builder.append("\"deviceId\":"); builder.append("\""); builder.append(DEVICE_ID); builder.append("\""); builder.append(","); builder.append("\"datasetId\":\"APPdata\"}"); String body = builder.toString(); System.out.println("body = " + body); AepDeviceStatusClient client = AepDeviceStatusClient.newClient() .appKey(APP_KEY).appSecret(APP_SECRET) .build(); QueryDeviceStatusRequest request = new QueryDeviceStatusRequest(); request.setBody(body.getBytes()); QueryDeviceStatusResponse response = client.QueryDeviceStatus(request); System.out.println("response.getBody() = " + JSON.toJSONString(response.getBody()));方法执行的结果是:response.getBody() = BaseApiResponse: statusCode=200 , contentType=application/json;charset=utf-8 , message=OK , headers={Transfer-Encoding=chunked, x-ag-timestamp=1742370464311, x-ag-route-cost=32, Server=elb, Connection=keep-alive, x-ag-proxied=true, x-ag-proxy-cost=0, Date=Wed, 19 Mar 2025 07:47:44 GMT, via=Telecom API Gateway, access-control-expose-headers=x-ag-request-id, x-ag-timestamp, x-ag-proxy-cost, cache-control, Transfer-Encoding, Date, Keep-Alive, Connection, user-agent, server, via, access-control-allow-origin, x-ag-proxied, x-ag-route-cost, content-type, access-control-expose-headers, access-control-allow-origin=*, x-ag-request-id=-2077230669-988849732, cache-control=no-cache, no-store, Content-Type=application/json;charset=utf-8, user-agent=Telecom API Gateway} , body={"code":0,"deviceStatus":{"value":"aBCYJAVgAAcogi4A9BcBATdWFBkDJeJgBwAAACwBAABiAQAAATwAAAABFAIjCGVWcGAAByhLRE0AAAIBno8W","timestamp":1742367273759},"desc":""} 我想获取body={"code":0,"deviceStatus":{"value":"aBCYJAVgAAcogi4A9BcBATdWFBkDJeJgBwAAACwBAABiAQAAATwAAAABFAIjCGVWcGAAByhLRE0AAAIBno8W","timestamp":1742367273759},"desc":""}这段数据,怎么处理
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值