'Change the representation of special characters in Gatling script
How can I change the representation of special characters in Gatling? I need to do this in token exchange, for example:
Here is sample response from server
1a0
{"Url":"/signalr","ConnectionToken":"gZlor6itFi4JZqAXzTMmsyy/hWxivJg+BRLbTyUwjPhAJBHpf7f2AzOSlFEFuosoeSqMuwN/d7Fask/lrFTKxzFUHZC8ArveNyOb957Cqss18lNSmwiIFiHixGzzC3YAe5YwTdK0Uvb3WVEUvZ/V7g==","ConnectionId":"1fbdd61e-8186-4312-9a51-986d983e28d4","KeepAliveTimeout":20.0,"DisconnectTimeout":30.0,"ConnectionTimeout":110.0,"TryWebSockets":false,"ProtocolVersion":"1.5","TransportConnectTimeout":5.0,"LongPollDelay":0.0}
0
And token from it
gZlor6itFi4JZqAXzTMmsyy/hWxivJg+BRLbTyUwjPhAJBHpf7f2AzOSlFEFuosoeSqMuwN/d7Fask/lrFTKxzFUHZC8ArveNyOb957Cqss18lNSmwiIFiHixGzzC3YAe5YwTdK0Uvb3WVEUvZ/V7g==
Here is the request, which I captured via Fiddler from web app
GET /signalr/connect?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20pVfF9mgAIu0Uylr9SFmQh3qA-TmG_fy8T60-f9C4bCFQYzTLbgvzNlBKknWZB_6T3ZaLa7z0bQBmvWILLDr_mXQHzlKr4EvGblzuIoeRrCm_vvL55tA0tDmtSoYhtA_mSxH27eG3jAYsXbDDQqqjmQUEtAQQhB6og_b8m2KQL211R14EXjkebDgiNoxkVKDqVKvatByveAq63RdOEzqd8QLNi72czK8SXtlfDttliSlKOYVypJvvdrhs0RmNM40VJBPZfZWd-Ew_I3cs8XKo9noynvWqm_yX7gDvDxNa_wP1lp3SkbExqlwuaJjtpvj3vKrfzTHm5iLLLCVrNZBOhwCjZiSQH_nrB17DG4_k7vWoJjDE3XX1W_ojuEjz3UNclhN28aRASWOJnoALW0Sr9JqRnQOoj8ncVKLnr-mQXr-XSsxNM1nBeUUihspocbjcvxlJYBiI81zzoyI4RKYeTaRKKjiJDvzq6EzFZ8wY3dnJPEKpSJXU7l0peTnHceld&connectionToken=gZlor6itFi4JZqAXzTMmsyy%2FhWxivJg%2BBRLbTyUwjPhAJBHpf7f2AzOSlFEFuosoeSqMuwN%2Fd7Fask%2FlrFTKxzFUHZC8ArveNyOb957Cqss18lNSmwiIFiHixGzzC3YAe5YwTdK0Uvb3WVEUvZ%2FV7g%3D%3D&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D&tid=10 HTTP/1.1
And the token
gZlor6itFi4JZqAXzTMmsyy%2FhWxivJg%2BBRLbTyUwjPhAJBHpf7f2AzOSlFEFuosoeSqMuwN%2Fd7Fask%2FlrFTKxzFUHZC8ArveNyOb957Cqss18lNSmwiIFiHixGzzC3YAe5YwTdK0Uvb3WVEUvZ%2FV7g%3D%3D
But when I extract all tokens and use them in Gatling, I have tokens with special characters, like here
gZlor6itFi4JZqAXzTMmsyy/hWxivJg+BRLbTyUwjPhAJBHpf7f2AzOSlFEFuosoeSqMuwN/d7Fask/lrFTKxzFUHZC8ArveNyOb957Cqss18lNSmwiIFiHixGzzC3YAe5YwTdK0Uvb3WVEUvZ/V7g==
And server responds with 400 error. My question is, how can I change the representation of this characters? Below my script, if additional info is required, let me know.
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class logingood extends Simulation {
val httpProtocol = http
.baseUrl("https://webapi.wage.iteodev.com")
.inferHtmlResources()
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
.proxy(Proxy("localhost", 8888).httpsPort(8888))
val headers_0 = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors")
val headers_1 = Map(
"Access-Control-Request-Headers" -> "authorization",
"Access-Control-Request-Method" -> "GET",
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors")
val headers_2 = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors",
"authorization" -> "Bearer ${authToken}")
val headers_3 = Map("Sec-Fetch-Mode" -> "no-cors")
val headers_7 = Map(
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors",
"content-type" -> "application/x-www-form-urlencoded; charset=UTF-8")
val uri1 = "https://api.wage.iteodev.com/signalr"
val uri2 = "https://frontend.iteodev.com/static/media/download-app-headline.a2c2b312.svg"
val scn = scenario("logingood")
.exec(http("request_0")
.post("/api/oauth/token")
.headers(headers_0)
.formParam("username", "[email protected]")
.formParam("password", "Zaq1@wsx")
.formParam("grant_type", "password")
.check(jsonPath("$..access_token").exists.saveAs("authToken"))
.resources(http("request_1")
.options("/api/account")
.headers(headers_1),
http("request_2")
.get("/api/account")
.headers(headers_2),
http("request_3")
.get(uri2)
.headers(headers_3),
http("request_4")
.options("/api/conversations/")
.headers(headers_1),
http("request_5")
.get("/api/conversations/")
.headers(headers_2),
http("request_6")
.options("/api/notifications")
.headers(headers_1)))
.exec(
exec(http("request_7")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.check(regex("""[a-zA-Z0-9=\/+]{152}""").find.saveAs("MyConnectionToken"))
.headers(headers_7)),
exec(http("request_8")
.get("/api/notifications")
.headers(headers_2)),
exec(http("request_9")
.get(uri1 + "/start?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionToken=${MyConnectionToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7))
exec(http("request_10")
.get(uri1 + "/connect?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionToken=${MyConnectionToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7))
exec(http("request_9")
.get(uri1 + "/start?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionToken=${MyConnectionToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7)))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
Solution 1:[1]
Have you tried disableUrlEncoding
?
It should be the method you are looking for : Gatling official docs: URL encoding
There is an example here in this Github issue: Doc: non-existing method disableUrlEncoding, which is fixed by now
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | anasmi |