gpt4 book ai didi

scala - 使用 Gatling 和 Content-Type 进行负载性能测试

转载 作者:行者123 更新时间:2023-12-04 11:00:48 27 4
gpt4 key购买 nike

我正在使用 gatling 对全新的 API 进行负载性能测试。这似乎相当简单且有据可查,但我面临的问题就像在标题上将 Content-Type 设置为“application/vnd.api+json”的请求一样简单。在执行 GET 操作时一切正常,但是在启动 POST 测试时,我得到一个

HTTP response:
status=
415 Unsupported Media Type
headers=
cache-control: [no-cache]
Content-Type: [application/vnd.api+json; charset=utf-8]
Date: [Fri, 08 Sep 2017 12:57:10 GMT]
Server: [nginx]
Vary: [Origin]
x-content-type-options: [nosniff]
x-frame-options: [SAMEORIGIN]
X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9]
x-runtime: [0.040662]
x-xss-protection: [1; mode=block]
Content-Length: [218]
Connection: [keep-alive]

body=
{"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]}

这是我用于 http 请求的 Scala 代码:
object PostTokenGcm {
val token = exec {
http("TestAPI POST /tokens")
.post("/tokens")
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
.body(StringBody(gcmTokenRequestBody)).asJSON
.check(status.is(201))
.check(bodyString.exists)
}}

好像没有设置Content-Type?

感谢您的任何领导!

最佳答案

在您的 POST您正在使用的定义 asJSON .根据 documentation about request headers 中的注释:

http("foo").get("bar").asJSON is equivalent to:

http("foo").get("bar")  .header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)  .header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)


...因此,标题设置为:

.headers(Map("Authorization"-> testApiToken,
"Content-Type"-> "application/vnd.api+json",
“接受”->“应用程序/vnd.api+json”))

... 被 asJSON 覆盖至 "application/json" (这是 HttpHeaderValues.ApplicationJson 的值)。

关于scala - 使用 Gatling 和 Content-Type 进行负载性能测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46118560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com