郭卫东 发表于 2024-9-2 04:40:22

postman哀求设置

1、哀求参数,只能是none、for-data、x-www…、raw等中的一个,不能多个。

https://i-blog.csdnimg.cn/direct/0dec30c7827641c395d48391edcdf6f9.png
2、哀求头类型

根据哀求头,选择参数,只能是none、for-data、x-www…、raw等中的一个,不能多个。
accept和Content-Type区别:
Content-Type:用于形貌发送的数据的格式。
Accept:用于形貌客户端盼望接收的数据的格式。
1. Content-Type
Content-Type 头字段用于告诉服务器(或客户端)请求或响应的主体数据的媒体类型(MIME 类型)。它指定了发送的数据的格式,以便接收方知道如何正确解析数据。
常见的 Content-Type 值:
application/json:表示数据是 JSON 格式。

http
复制代码
Content-Type: application/json
示例请求体:

json
复制代码
{
"name": "John",
"age": 30
}
application/x-www-form-urlencoded:表示数据是 URL 编码的表单数据,通常在表单提交时使用。

http
复制代码
Content-Type: application/x-www-form-urlencoded
示例请求体:

makefile
复制代码
name=John&age=30
multipart/form-data:用于文件上传的表单数据,允许发送文件和键值对。

http
复制代码
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
text/plain:表示数据是纯文本格式。

http
复制代码
Content-Type: text/plain
text/html:表示数据是 HTML 格式。

http
复制代码
Content-Type: text/html
2. Accept
Accept 头字段用于告诉服务器,客户端希望接收到的响应内容的媒体类型。服务器会根据这个头字段来确定返回数据的格式,如果可能的话。

使用场景:
客户端发送请求时:客户端通过 Accept 头字段告诉服务器,它能够处理哪些格式的数据。服务器通常会根据这个信息决定返回什么类型的数据。如果服务器无法提供所请求的格式,可能会返回 406 Not Acceptable 状态码。
常见的 Accept 值:
application/json:客户端希望接收到 JSON 格式的数据。

http
复制代码
Accept: application/json
text/html:客户端希望接收到 HTML 格式的数据。

http
复制代码
Accept: text/html
*/*:客户端能够接受所有类型的数据。

http
复制代码
Accept: */*
application/xml:客户端希望接收到 XML 格式的数据。

http
复制代码
Accept: application/xml
3、案例

CosyVoice的一些哀求
https://github.com/FunAudioLLM/CosyVoice
1.x-www-form-urlencoded格式
curl -X 'POST' \
'http://172.31.208.3:50000/api/inference/sft' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'tts=%E5%B8%8C%E6%9C%9B%E4%BD%A0%E4%BB%A5%E5%90%8E%E8%83%BD%E5%A4%9F%E5%81%9A%E7%9A%84%E6%AF%94%E6%88%91%E8%BF%98%E5%A5%BD%E5%91%A6%E3%80%82&role=%E4%B8%AD%E6%96%87%E5%A5%B3'
https://i-blog.csdnimg.cn/direct/8cace8bc70a6458884352ceacca8d007.png
https://i-blog.csdnimg.cn/direct/d3f72d55687042cb95c920b214f4e2a4.png
2.form-data格式
curl -X 'POST' \
'http://172.31.208.3:50000/api/inference/zero-shot' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'tts=没有什么能够阻挡,你对自由的向往,天马行空的生涯,你的心了无牵挂' \
-F 'prompt=我做的装置可不是骗人的。想瞒着外面的人解决这场灾难,就必须用到它。只不过,那个装置不是为你准备的罢了。' \
-F 'audio=@vo_LLZAQ001_12_dottore_06.wav;type=audio/wav'
https://i-blog.csdnimg.cn/direct/42f867ec89db478ab7a8dede07922063.png
https://i-blog.csdnimg.cn/direct/d437fbc4028344198396f888fa9c8aea.png
3.form-data格式
curl -X 'POST' \
'http://172.31.208.3:50000/api/inference/cross-lingual' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'tts=没有什么能够阻挡,你对自由的向往,天马行空的生涯,你的心了无牵挂' \
-F 'audio=@vo_LLZAQ001_12_dottore_06.wav;type=audio/wav'
https://i-blog.csdnimg.cn/direct/99d1410d9ff742dcbec2c598b6a2c827.png
https://i-blog.csdnimg.cn/direct/57054517b0d5457e8808e2a1cd946bb8.png
4.x-www-form-urlencoded格式
curl -X 'POST' \
'http://172.31.208.3:50000/api/inference/instruct' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'tts=%E6%B2%A1%E6%9C%89%E4%BB%80%E4%B9%88%E8%83%BD%E5%A4%9F%E9%98%BB%E6%8C%A1%2C%E4%BD%A0%E5%AF%B9%E8%87%AA%E7%94%B1%E7%9A%84%E5%90%91%E5%BE%80%2C%E5%A4%A9%E9%A9%AC%E8%A1%8C%E7%A9%BA%E7%9A%84%E7%94%9F%E6%B6%AF%2C%E4%BD%A0%E7%9A%84%E5%BF%83%E4%BA%86%E6%97%A0%E7%89%B5%E6%8C%82&role=%E4%B8%AD%E6%96%87%E5%A5%B3&instruct=%3Claughter%3E%3C%2Flaughter%3E'
https://i-blog.csdnimg.cn/direct/00ed0903c225428f948a1199f9edc303.png
https://i-blog.csdnimg.cn/direct/ed309fa3324e496bab0aeed39a1afc41.png
4、测压

这个Runner是串行测试,不是并行,别被网上的教程误导了。
可以用python脚本实现并行:
在Python中,如果你想并行发送多个哀求到同一个接口,可以使用以下几种方法:
线程池 (concurrent.futures.ThreadPoolExecutor)
进程池 (concurrent.futures.ProcessPoolExecutor)
异步IO (asyncio + aiohttp)
https://i-blog.csdnimg.cn/direct/1c777f8e41eb42149708e548c7466f4d.png
import asyncio
import aiohttp

async def fetch_url(session, url):
    async with session.get(url) as response:
      status_code = response.status
      content = await response.text()
      return status_code, content[:500]# 只返回状态码和前100字符的响应内容

async def main():
    url = "http://172.31.208.3:8077"
    async with aiohttp.ClientSession() as session:
      tasks =
      results = await asyncio.gather(*tasks)
      for status_code, content in results:
            print(f"Status: {status_code}, Content: {content}")

# 运行异步任务
asyncio.run(main())

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: postman哀求设置