需要邮递员curl网址的等效加特林scala代码
您能为下面的身份验证请求逻辑上写一个等效的gatling scala代码吗?首先,我需要使用gatling scala获得一个auth请求及其响应。以下是PostMan中的身份验证curl请求,它工作正常,我的意思是给出201响应,但是我使用git url github
在加特林得到400响应根据curl请求生成:
curl 'https://api.platform.com/auth/oauth/token' -H 'Accept: application/json, text/plain, */*' -H 'Referer: https://api-origin.cloud/dev/reservations-web/signin' -H 'Origin: https://api.origin.cloud' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Authorization: Basic aWtyd3VnaDM4NzFnaHc4cmduN3E4M2c2c3I=' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'grant_type=password&username=abc.xyc1%40abc.com&password=Password1%21' --compressed
下面是我尝试生成的scala等效代码,但得到了400个响应
package simulations
import baseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.core.session
import io.gatling.http.Predef._
import scala.concurrent.duration.DurationInt
import scala.util.Random
class ogrebattledriverPostAccessToken extends BaseSimulation {
exec(
http("HTTP Request auth")
.post("https://api.platform.com/auth/oauth/token")
.header("Content-Type","application/x-www-form-urlencoded")
.formParam("grant_type","password")
.formParam("username", "TableTopEng%40xxxs.com")
.formParam("password", "actual password")
.check(status is 200)
.check(jsonPath("$.access_token").saveAs("access_token"))
.check(jsonPath("$.token_type").saveAs("token_type"))
)
//val PostData=jsonFile("input-json.json").circular
def name() = Random.nextInt(Integer.MAX_VALUE).toString
//val headers_10 = Map("Content-Type" -> """application/json""","Authorization","${token_type} + ${access_token}" )
def getSpecificOgreID()={
repeat(140000){
exec(flushHttpCache)
feed(usersDataSource)
.exec(http("PostRequestPerformanceTestingOgreBattleDriver")
.post("https://api.tabletop-stage.tiamat-origin.cloud/dev/ogre-battledriver/Organizations")
// .headers(headers_10)
.header("Authorization", "${token_type} + ${access_token}")
.body(StringBody(session =>
s"""
|{
| "name": "${name()}",
| "latitude": 66.256538,
| "longitude": -95.934502,
| "phoneNumber": "555-555-5555",
| "emailAddress": "perftest1@perftest1.com",
| "website": "https://perftest1",
| "streetLine1": "123 perftest1.",
| "streetLine2": "Ste 400",
| "city": "Omaha",
| "state": "NE",
| "zipCode": "98002"
|}
""".stripMargin)).asJSON
.check(status.in(200,201))//checkforaspecificstatus
.check(jsonPath(path="$.name").saveAs(key="name")))//checkforaspecificstatus
.exec{session=>println(session);session}//parameterfortheorgIdgoeshere
.pause(1)
}
}
// add a scenario
val scn = scenario("Battle Driver Get Orgs ")
.forever() { // add in the forever() method - users now loop forever
exec(getSpecificOgreID())
}
我在Intellij编辑器中遇到错误
20:22:56.563 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'access_token' is defined
有人可以从邮递员curl请求上面写一个逻辑的加特林Scala代码吗?