API Path
/aipaas/ocr/v1/xingchenOcr/multimodal
请求协议
HTTPS
请求方法
POST
请求头部:
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | 内容类型 | application/json | application/json | |||
| X-APP-ID | 是 | 控制台--应用管理--AppID | |||||
| Device-Uuid | 是 | 设备管理-设备uuid | |||||
| Authorization | 是 | 鉴权信息 |
请求参数 Json
Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| seqid | 接口跟踪ID,每次调用需不同,可使用UUID, 用于日志排除、链路跟踪,最短1字符,最长256字符 | 是 | [string] | 0 | b8fbd1e7-1fa2-46c7-a6ec-7e82db5885dd | |
| image_type | 图片类型:0-image必须为url【默认】,1-image必须为base64,支持图片和pdf | 否 | [int] | 0:图片base64,1:图片url,2:pdf文件base64,3:pdf文件url | 0 | 0 |
| image | 图片或pdf的base64编码数据或url,具体要求参考4中请求参数说明 | 是 | [string] | 0 | /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKB/4Q+z+COm+LLTxnZzXIvRqEutX9lLa | |
| html_escape | 是否html转义,用于解决xss漏洞【默认true】 | 否 | [boolean] | 0 | true | |
| callback_url | 回调地址,必填 | 否 | [string] | 0 | ||
| return_mode | 结果返回模式,0:push,1:pull,默认为0。push模式即提供callback_url接收最终结果回调;pull模型即通过大模型异步调用结果回查接口查询最终调用结果,接口文档详见开发指南下的大模型异步调用结果回查。 | 否 | [int] | 32 |
响应内容:
返回结果
成功 (200)
Json
Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| seqid | 请求序列号,usid,请求的唯一标识,透传 | 是 | [string] | 0 | b8fbd1e7-1fa2-46c7-a6ec-7e82db5885dd | |
| code | 状态响应码。参考状态码说明 | 是 | [string] | 0 | 10000 | |
| message | 调用结果描述 | 是 | [string] | 0 | 请求成功 | |
| flag | 业务上成功或失败:1成功,0失败 | 是 | [int] | 0 | 1 | |
| data | 同步任务直接返回结果 | 是 | [object] | 0 | ||
| data>>timeSecond | 分析耗时,单位秒 | 是 | [double] | 0 | 1.25 | |
| data>>words_result | 一次输出所有结果,如果识别失败,或者图片中本身就没有文字会返回[] | 是 | [array] | 0 | [{"total_page_number":2,"markdown":"识别markdown格式数据","pages":[{"page_id":0,"width":1654,"height":2339,"discarded_blocks":[],"content":[{"type":"text","angle":0,"index":0,"pos":[100,120,500,200],"text":"⽰例⽂本"},{"type":"image","angle":0,"blocks":[{"type":"image_body","angle":0,"index":5,"pos":[60,214,536,426],"image_url":"/images/2026-03-16/5aaf2a74-8494-4fad-87a1-977998dbeacd.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260316%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260316T022043Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=cf55f9a29ee57847460b5de592f3579804e59997708f4dd59bc6be62ada22f24"},{"type":"image_caption","angle":0,"index":7,"pos":[46,431,547,464],"content":"Figure 1. We introduce a language-model-based motion understanding and generation framework that takes in any of the audio/motion/text modalities and outputs the desired target modality. Coupled with our generative pre-training strategy, our model demonstrates competitive performance on an array of tasks, showing promising signs toward unified verbal and non-verbal language of human motions."}]},{"type":"table","angle":0,"blocks":[{"type":"table_body","angle":0,"index":4,"pos":[271,649,1589,1975],"html":"html格式的表格数据","image_url":"http://172.16.113.200:29253/test/ocr/images/2026-03-12/b88dfdb7-ca15-4dd1-b14a-a80be4c993b0.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260312%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260312T073639Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=7e6f6825c7545eef53fda4cbfc79dc9ab068f2a82410fcbe08084e82a9554ecd"}],"index":4,"pos":[271,649,1589,1975]}]}]}] | |
| data>>words_result>>total_page_number | 解析的图片或文档的总页数 | 是 | [int] | 0 | 2 | |
| data>>words_result>>markdown | 识别到的结果,用markdown格式输出 | 是 | [string] | 0 | 识别markdown格式数据 | |
| data>>words_result>>pages | 是 | [array] | 0 | [{"page_id":0,"width":1654,"height":2339,"discarded_blocks":[],"content":[{"type":"text","angle":0,"index":0,"pos":[100,120,500,200],"text":"⽰例⽂本"},{"type":"image","angle":0,"blocks":[{"type":"image_body","angle":0,"index":5,"pos":[60,214,536,426],"image_url":"/images/2026-03-16/5aaf2a74-8494-4fad-87a1-977998dbeacd.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260316%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260316T022043Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=cf55f9a29ee57847460b5de592f3579804e59997708f4dd59bc6be62ada22f24"},{"type":"image_caption","angle":0,"index":7,"pos":[46,431,547,464],"content":"Figure 1. We introduce a language-model-based motion understanding and generation framework that takes in any of the audio/motion/text modalities and outputs the desired target modality. Coupled with our generative pre-training strategy, our model demonstrates competitive performance on an array of tasks, showing promising signs toward unified verbal and non-verbal language of human motions."}]},{"type":"table","angle":0,"blocks":[{"type":"table_body","angle":0,"index":4,"pos":[271,649,1589,1975],"html":"html格式的表格数据","image_url":"http://172.16.113.200:29253/test/ocr/images/2026-03-12/b88dfdb7-ca15-4dd1-b14a-a80be4c993b0.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260312%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260312T073639Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=7e6f6825c7545eef53fda4cbfc79dc9ab068f2a82410fcbe08084e82a9554ecd"}],"index":4,"pos":[271,649,1589,1975]}]}] | ||
| data>>words_result>>pages>>page_id | 当前页的页码,从0开始 | 是 | [int] | 0 | 0 | |
| data>>words_result>>pages>>width | 页面宽度(像素) | 是 | [int] | 0 | 1654 | |
| data>>words_result>>pages>>height | 页面高度(像素) | 是 | [int] | 0 | 2339 | |
| data>>words_result>>pages>>discarded_blocks | 存储页眉和页脚相关的信息,如果没有页眉页脚信息,此字段为空列表 | 是 | [array] | 0 | [] | |
| data>>words_result>>pages>>discarded_blocks>>type | 可能得类型为header、footer | 是 | [string] | 0 | ||
| data>>words_result>>pages>>discarded_blocks>>angle | 文本旋转角度 | 是 | [int] | 0 | ||
| data>>words_result>>pages>>discarded_blocks>>index | 当前页内块序号 | 是 | [int] | 0 | ||
| data>>words_result>>pages>>discarded_blocks>>pos | 版面块坐标,内部为int类型数字,代表左上右下坐标共4个值 | 是 | [array] | 0 | ||
| data>>words_result>>pages>>discarded_blocks>>text | ocr识别到的文本 | 是 | [string] | 0 | ||
| data>>words_result>>pages>>content | 内部结构参考返回结果说明 | 是 | [array] | 0 | [{"type":"text","angle":0,"index":0,"pos":[100,120,500,200],"text":"⽰例⽂本"},{"type":"image","angle":0,"blocks":[{"type":"image_body","angle":0,"index":5,"pos":[60,214,536,426],"image_url":"/images/2026-03-16/5aaf2a74-8494-4fad-87a1-977998dbeacd.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260316%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260316T022043Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=cf55f9a29ee57847460b5de592f3579804e59997708f4dd59bc6be62ada22f24"},{"type":"image_caption","angle":0,"index":7,"pos":[46,431,547,464],"content":"Figure 1. We introduce a language-model-based motion understanding and generation framework that takes in any of the audio/motion/text modalities and outputs the desired target modality. Coupled with our generative pre-training strategy, our model demonstrates competitive performance on an array of tasks, showing promising signs toward unified verbal and non-verbal language of human motions."}]},{"type":"table","angle":0,"blocks":[{"type":"table_body","angle":0,"index":4,"pos":[271,649,1589,1975],"html":"html格式的表格数据","image_url":"http://172.16.113.200:29253/test/ocr/images/2026-03-12/b88dfdb7-ca15-4dd1-b14a-a80be4c993b0.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260312%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260312T073639Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=7e6f6825c7545eef53fda4cbfc79dc9ab068f2a82410fcbe08084e82a9554ecd"}],"index":4,"pos":[271,649,1589,1975]}] | |
| data>>words_result>>pages>>content>>type | 可能类型包括text、image、title、equation、table | 是 | [string] | 0 | text | |
| data>>words_result>>pages>>content>>angle | 文本旋转角度 | 否 | [int] | 0 | 0 | |
| data>>words_result>>pages>>content>>index | 当前页内块序号 | 是 | [int] | 0 | 0 | |
| data>>words_result>>pages>>content>>pos | 版面块坐标,内部为int类型数字,代表左上右下坐标共4个值 | 否 | [array] | 0 | [100,120,500,200] | |
| data>>words_result>>pages>>content>>text | ocr识别到的文本 | 否 | [string] | 0 | ⽰例⽂本 | |
| data>>words_result>>pages>>content>>blocks | type类型是image或者talbe时有此字段 | 是 | [array] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>type | 可能取值table_body、table_captaoin、image_body、image_caption | 是 | [string] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>angle | 文本旋转角度 | 是 | [int] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>index | 块序号 | 是 | [int] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>pos | 版面块坐标,左上右下坐标点,内部为int类型 | 是 | [array] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>content | type为image_caption或table_caption时有此字段 | 否 | [string] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>image_url | type为image_body或table_body时有此字段,图生上传s3后的url | 否 | [string] | 0 | ||
| data>>words_result>>pages>>content>>blocks>>html | type为table_body时有此字段 | 否 | [string] | 0 |
成功 (200)
Json
Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|
成功示例
{
"seqid": "test_seq0",
"code": "10000",
"message": "请求成功",
"flag": 1,
"data": {
"timeSecond": 1.25,
"words_result": [{
"total_page_number": 2,
"markdown": "识别markdown格式数据",
"pages": [{
"page_id": 0,
"width": 1654,
"height": 2339,
"discarded_blocks": [
],
"content": [{
"type": "text",
"angle": 0,
"index": 0,
"pos": [
100,
120,
500,
200
],
"text": "⽰例⽂本"
},
{
"type": "image",
"angle": 0,
"blocks": [{
"type": "image_body",
"angle": 0,
"index": 5,
"pos": [
60,
214,
536,
426
],
"image_url": "/images/2026-03-16/5aaf2a74-8494-4fad-87a1-977998dbeacd.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260316%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260316T022043Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=cf55f9a29ee57847460b5de592f3579804e59997708f4dd59bc6be62ada22f24"
},
{
"type": "image_caption",
"angle": 0,
"index": 7,
"pos": [
46,
431,
547,
464
],
"content": "Figure 1. We introduce a language-model-based motion understanding and generation framework that takes in any of the audio/motion/text modalities and outputs the desired target modality. Coupled with our generative pre-training strategy, our model demonstrates competitive performance on an array of tasks, showing promising signs toward unified verbal and non-verbal language of human motions."
}
]
},
{
"type": "table",
"angle": 0,
"blocks": [{
"type": "table_body",
"angle": 0,
"index": 4,
"pos": [
271,
649,
1589,
1975
],
"html": "html格式的表格数据",
"image_url": "http://172.16.113.200:29253/test/ocr/images/2026-03-12/b88dfdb7-ca15-4dd1-b14a-a80be4c993b0.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260312%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260312T073639Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=7e6f6825c7545eef53fda4cbfc79dc9ab068f2a82410fcbe08084e82a9554ecd"
}],
"index": 4,
"pos": [
271,
649,
1589,
1975
]
}
]
}]
}]
}
}
星辰文档解析依托前沿的多模态融合算法,攻克图像及PDF等复杂格式的识别与解析难题。产品集成文字识别、高精表格还原、版面逻辑分析及语义阅读语序重构等多项核心能力,实现了对文档逻辑结构的高精度还原。其通过构建坚实的底层解析底座,为企业级知识问答、AI Agent建设及大规模文档数据治理提供强有力的技术赋能。当前能力为异步调用接口,使用时请注意
| 修订日期 | 算法版本号 | 修订内容 |
|---|---|---|
| 2026-03-16 | V1.0.0 | 首版本发布 |
服务接口调用时需要严格遵循服务鉴权规则,服务调用鉴权规则请参见:开发指南 - 接口签名认证。
html_escape)值为true时对识别出的文本做html转义,上层调用不用担心xss漏洞问题,值为False时识别出的文本原样输出,上层调用方如果需要把识别结果展示在web页面上需要自己修复xss漏洞问题返回的pages识别到的文本的示例:
[
{
"page_id": 0,
"width": 1654,
"height": 2339,
"discarded_blocks": [
],
"content": [
{
"type": "text",
"angle": 0,
"index": 0,
"pos": [
100,
120,
500,
200
],
"text": "⽰例⽂本"
},
{
"type": "image",
"angle": 0,
"blocks": [
{
"type": "image_body",
"angle": 0,
"index": 5,
"pos": [
60,
214,
536,
426
],
"image_url": "/images/2026-03-16/5aaf2a74-8494-4fad-87a1-977998dbeacd.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260316%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260316T022043Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=cf55f9a29ee57847460b5de592f3579804e59997708f4dd59bc6be62ada22f24"
},
{
"type": "image_caption",
"angle": 0,
"index": 7,
"pos": [
46,
431,
547,
464
],
"content": "Figure 1. We introduce a language-model-based motion understanding and generation framework that takes in any of the audio/motion/text modalities and outputs the desired target modality. Coupled with our generative pre-training strategy, our model demonstrates competitive performance on an array of tasks, showing promising signs toward unified verbal and non-verbal language of human motions."
}
]
},
{
"type": "table",
"angle": 0,
"blocks": [
{
"type": "table_body",
"angle": 0,
"index": 4,
"pos": [
271,
649,
1589,
1975
],
"html": "html格式的表格数据",
"image_url": "http://172.16.113.200:29253/test/ocr/images/2026-03-12/b88dfdb7-ca15-4dd1-b14a-a80be4c993b0.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20260312%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260312T073639Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=7e6f6825c7545eef53fda4cbfc79dc9ab068f2a82410fcbe08084e82a9554ecd"
}
],
"index": 4,
"pos": [
271,
649,
1589,
1975
]
}
]
}
]
content中字段说明:
| 属性名称 | 类型 | 说明 | 备注 |
|---|---|---|---|
| type | string | 可能的取值包括: 1.text:表示正文段落文字内容。 2.title:表示标题文字。 3.image:表示图像元素区域。 4.table:表示表格的内容,包括表格标题和内容。5.equation:公式 |
当type类型为image时,content中的结构体类型为:
| 属性名称 | 类型 | 说明 | 备注 |
|---|---|---|---|
| type | string | type为image | |
| angle | int | 文本旋转角度 | |
| index | int | 当前块的索引值 | 从0开始,数值不一定连续 |
| pos | list | 当前版面块的坐标 | 左上右下的坐标点,int类型 |
| blocks | list | 识别到的图片的信息 | list内部为结构体长度为1或者2,一定包含 image_body,可能包含image_caption |
| +type | string | type取值可能为: 1.image_body:图片内容 2.image_caption:图片标题 |
|
| +angle | int | 文本旋转角度 | |
| +index | int | 当前块的索引值 | 从0开始,数值不一定连续 |
| +pos | list | 当前版面块的坐标 | 左上右下的坐标点,int类型 |
| +image_url | string | 图片url,当type为image_body时有此字段 | 如果识别到的url上传s3识别,则image_url为:http://error.com ;此url没有意义,只是表明此处有图片 |
| +content | string | 图片标题,当type为image_caption时有此字段 |
| 属性名称 | 类型 | 说明 | 备注 |
|---|---|---|---|
| type | string | type为table | |
| angle | int | 文本旋转角度 | |
| index | int | 当前块的索引值 | 从0开始,数值不一定连续 |
| pos | list | 当前版面块的坐标 | 左上右下的坐标点,int类型 |
| blocks | list | 识别到的图片的信息 | list内部为结构体长度为1或者2,一定包含 image_body,可能包含image_caption |
| +type | string | 取值可能为 1.table_body:表格内容 2.table_caption:表格标题 |
|
| +angle | int | 文本旋转角度 | |
| +index | int | 当前块的索引值 | 从0开始,数值不一定连续 |
| +pos | list | 当前版面块的坐标 | 左上右下的坐标点,int类型 |
| +image_url | string | 把表格生成图片并上传s3后的图片url | 当type为table_body时有此字段 |
| +html | string | html格式的表格信息 | 当type为table_body时有此字段 |
| +content | string | 表格的标题 | 当type为table_caption有此字段 |
| 属性名称 | 类型 | 说明 | 备注 |
|---|---|---|---|
| type | string | ||
| angle | int | 文本旋转角度 | |
| index | int | 当前块的索引值 | 从0开始,数值不一定连续 |
| pos | list | 当前版面块的坐标 | 左上右下的坐标点,int类型 |
| text | string | 识别到的内容 |
discarded_blocks中字段说明:
| 属性名称 | 类型 | 说明 | 备注 |
|---|---|---|---|
| type | string | 可能的取值包括: 1.header:页眉。 2.footer:页脚。 |
|
| angle | int | 文本旋转角度 | |
| index | int | 当前块的索引值 | 从0开始,数值不一定连续 |
| pos | list | 当前版面块的坐标 | 左上右下的坐标点,int类型 |
| text | string | 识别到的内容 |
pos绘制区域示例代码:
##pdf 文件使用返回的bbox绘制区域示例
import fitz # pip install pymupdf
# 打开 PDF
pdf_path = "example.pdf"
doc = fitz.open(pdf_path)
# 假设在第1页画框
page = doc[0]
# 需要画的框的坐标 (x0, y0, x1, y1)这个坐标就是返回的bbox
# 左上角 (x0, y0),右下角 (x1, y1),单位是 PDF 点(1点 = 1/72 英寸)
#例如bbox=[100,150,300,200]则绘制方法如下
bbox = [100,150,300,200]
rect = fitz.Rect(bbox[0], bbox[1], bbox[2], bbox[3])
# 在 PDF 上画一个红色矩形
shape = page.new_shape()
shape.draw_rect(rect)
shape.finish(color=(1, 0, 0), width=2) # RGB颜色(1,0,0) = 红色,线宽 2
shape.commit()
# 保存到新文件
doc.save("example_boxed.pdf")
doc.close()
# 坐标说明:PDF 的坐标原点在 左上角(x 向右增加,y 向下增加)
##图片文件使用返回的bbox绘制区域示例代码
from PIL import Image, ImageDraw
# 打开图像
img = Image.open("example.jpg")
draw = ImageDraw.Draw(img)
# 例如返回的bbox=[50,60,200,150]
bbox = [50, 60, 200, 150]
# 画红色矩形框
draw.rectangle(bbox, outline="red", width=3)
# 保存结果
img.save("boxed.jpg")
{
"seqid": "test_seq0",
"image": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgK===","
"callback_url":"http://callbackUrl"
"html_escape": False,
"image_type":1
}
| 状态码 | 状态描述 | 状态说明 |
|---|---|---|
| 10000 | 请求成功 | |
| 10202 | 算法推理异常 | 算法推理失败 |
| 10203 | 文件上传异常 | 结果图片上传ceph/minIO失败 |
| 10304 | 服务入参错误 | 部分参数存在限制说明,会针对入参做校验返回 |
| 10903 | 服务执行失败 | 服务执行失败(可能存在组件连接异常、算法模型程序运行异常等情况,导致服务无法正常运行) |
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
/**
* 为保证示例可以正常运行,请确认maven中是否存在以下依赖:
* <dependency>
* <groupId>cn.hutool</groupId>
* <artifactId>hutool-all</artifactId>
* <version>5.8.29</version>
* </dependency>
* <dependency>
* <groupId>com.alibaba</groupId>
* <artifactId>fastjson</artifactId>
* <version>1.2.83</version>
* </dependency>
*/
public class Example {
public static void example() {
try {
// 算法调用地址,请根据实际情况修改
String url = "算法调用地址";
// 设置请求头
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Device-Uuid", "2018619061498245122");
headers.put("X-APP-ID", "你实际的AppId");
headers.put("Authorization", "你实际的Authorization");
// 设置请求参数,请根据实际情况修改
String requestString = "{\n" +
" \"callback_url\":\"\",\n" +
" \"image\":\"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKB/4Q+z+COm+LLTxnZzXIvRqEutX9lLa\",\n" +
" \"html_escape\":true,\n" +
" \"seqid\":\"b8fbd1e7-1fa2-46c7-a6ec-7e82db5885dd\",\n" +
" \"image_type\":0\n" +
"}";
// 发起HTTP请求
HttpResponse response = HttpRequest.post(url)
.headerMap(headers, true)
.body(requestString)
.execute();
// 输出响应结果
System.out.println(response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
example();
}
}
import json
import hashlib
import hmac
import time
import re
import urllib.parse
import requests
import warnings
from datetime import datetime
import logging
# 配置日志,设置日志级别为INFO,并指定日志格式
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 配置环境变量
X_APP_ID = "yourAppId"
AUTHORIZATION = "yourAuthorization"
# 请求的URL
url = "算法调用地址"
# 请求数据
request_data = {
"callback_url":"",
"image":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKB/4Q+z+COm+LLTxnZzXIvRqEutX9lLa",
"html_escape":True,
"seqid":"b8fbd1e7-1fa2-46c7-a6ec-7e82db5885dd",
"image_type":0
}
# 构建请求头
headers = {
"Content-Type": "application/json",
"Device-Uuid": "2018619061498245122",
"X-APP-ID": X_APP_ID,
"Authorization": AUTHORIZATION
}
def timeSimple(timestamp):
# 将时间戳转换为HH:MM:SS格式的时间字符串
dt_object = datetime.fromtimestamp(timestamp)
formatted_time = dt_object.strftime("%H:%M:%S")
return formatted_time
def send_request(url):
try:
start_time = time.time()
logging.info(f"请求路径: {url}")
logging.info(f"开始发送: {timeSimple(start_time)}")
with requests.post(
url, json=request_data, headers=headers, stream=True, verify=False
) as response:
first_packet_time = None
if response.status_code == 200:
logging.info(f"接受到返回: {timeSimple(time.time())}")
for chunk in response.iter_content(chunk_size=1024):
if chunk:
if first_packet_time is None:
first_packet_time = time.time()
logging.info(
f"Received chunk: {timeSimple(time.time())} {chunk.decode('utf-8')}"
)
end_time = time.time()
logging.info(f"Time to first byte (TTFB): {first_packet_time - start_time:.3f} seconds")
logging.info(f"Request completed in {end_time - start_time:.3f} seconds")
else:
logging.error(f"Request failed with status code {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
# 发送请求
send_request(url)
logging.info(f"headers = {headers}")