---- REQUEST: ----
POST http://idpt.company.com/ids/connect/token HTTP/1.1
Authorization: Basic bW9iaWxlX2NsaWVudDptb2JpbGVfc2VjcmV0
host: idpt.company.com
content-type: application/x-www-form-urlencoded; charset=utf-8
content-length: 103
Connection: keep-alive
username=theusername&password=thepassword&scope=small&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password
.exec(
http("getToken")
.post("https://id.company.com/ids/connect/token")
.headers(Map("Content-Type" -> "application/x-www-form-urlencoded; charset=utf-8" , "Authorization" -> "Basic bW9iaWxlX2xxxxxxmV0"))
.body(StringBody("username=theusername&password=thepassword&scope=small&proxy=http%3X%2F%2Flocalhost%3A8888&grant_type=password"))
.asFormUrlEncoded
)
I want to do a call to a token-service like this in Gatling:
---- REQUEST: ----
POST http://idpt.company.com/ids/connect/token HTTP/1.1
Authorization: Basic bW9iaWxlX2NsaWVudDptb2JpbGVfc2VjcmV0
host: idpt.company.com
content-type: application/x-www-form-urlencoded; charset=utf-8
content-length: 103
Connection: keep-alive
username=theusername&password=thepassword&scope=small&proxy=http%3X%2F%2Flocalhost%3A8888&grant_type=password
This (POST) request should respons with a token.
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
.headers(Map("Content-Type" -> "application/x-www-form-urlencoded; charset=utf-8" , "Authorization" -> "Basic c29tZV9jbGllbnQ6c29tZV9zZWNyZXQ="))
Or as a separate function?
package com.site
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
class idpSimulation extends Simulation{
val httpConf = http
.baseURL("https://id.site.com/ids")
.acceptEncodingHeader("gzip,deflate")
.headers(Map("Content-Type" -> "application/x-www-form-urlencoded; charset=utf-8"))
.authorizationHeader("Basic bW9PaWxlX2NsaWZudDptbpJpxVfc2VjcmV0")
.disableUrlEscaping
val scn = scenario("Scenario")
.feed(csv("data/testdata.csv").random)
.exec(
http("getToken")
.post("/connect/token").basicAuth("${MemberId}", "password")
//.body(StringBody("username=${MemberId}&password=password&scope=legacy&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password"))
.asFormUrlEncoded
.check(jsonPath("$.access_token").exists.saveAs("token")))
setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
}
...scope=legacy&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password
=========================HTTP request:headers=Accept-Encoding: gzip,deflateContent-Type: application/x-www-form-urlencodedAuthorization: Basic bW9iaWxlXsNsaWVddDptb2JpbwVfc2VjcmV0Content-Length: 68Connection: keep-aliveHost: id.site.comAuthorization: Basic ODMxNTU3MjMdMzpwYdNzMTIzAccept: */*compositeByteData=scope=legacy&proxy=http%3Z%2F%2Flocalhost%3A8988&grant_type=passwordrealm=Realm{principal='removedbyme', password='pass123', scheme=BASIC, realmName='', nonce='', algorithm='MD5', response='', qop='auth', nc='00000001', cnonce='', uri='null', methodName='GET', useAbsoluteURI='true', omitQuery='false'}=========================HTTP response:status=400 Bad Requestheaders= Content-Type: [text/html; charset=us-ascii]Server: [Microsoft-HTTPAPI/2.0]Date: [Fri, 09 Jan 2015 21:59:34 GMT]nnCoection: [close]Content-Length: [339]
body=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><HTML><HEAD><TITLE>Bad Request</TITLE><META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD><BODY><h2>Bad Request - Invalid Header</h2><hr><p>HTTP Error 400. The request has an invalid header name.</p></BODY></HTML>
<<<<<<<<<<<<<<<<<<<<<<<<<
val httpConf = http
.baseURL("https://id.site.com/ids")
.acceptEncodingHeader("gzip,deflate")
.headers(Map("Content-Type" -> "application/x-www-form-urlencoded; charset=utf-8"))
//.authorizationHeader("Basic bW9PaWxlX2NsaWZudDptbpJpxVfc2VjcmV0") //--- remove this authorization headers
.basicAuth(username: "<yourUserName>",password: "<yourPassword>")
.disableUrlEscaping
.exec(
http("getToken")
.post("/connect/token"
)
//.basicAuth("${MemberId}", "password") -- remove this from here
//.body(StringBody("username=${MemberId}&password=password&scope=legacy&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password"))
.asFormUrlEncoded
.check(jsonPath("$.access_token").exists.saveAs("token")))
.body(StringBody("username=${MemberId}&password=password&scope=legacy&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password")scope=legacy&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password".body(StringBody("scope=legacy&proxy=http%3A%2F%2Flocalhost%3A8888&grant_type=password"))