2017-09-08 66 views
5

Yepyeni bir API üzerinde yük performans testi için gatling kullanıyorum. Oldukça kolay ve iyi bir şekilde belgelenmiş gibi görünüyor, ancak POST olarak Header'da 'application/vnd.api + json' olarak ayarlanmış Content-Type ile ilgili bir istekle karşılaşıyorum.Gatling ve Content-Type ile yükleme performans testi

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) 
}} 

O olmadığını görünüyor: POST testi başlatırken GET şeyler yapıyor ama ne zaman tek şey http isteği için kullanıyorum scala kodudur Ben İşte

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"}]} 

olsun iyi çalışıyor İçerik Türü ayarlanıyor mu?

Herhangi bir sorunuz için teşekkür ederiz!

+1

Bu, API'da bir hata mı olabilir? Aynı isteği postacı gibi bir araçla yaparsanız API bunu kabul eder mi? – pedromss

+0

Postman @pedromss'i kullandım ve istenen 201'i yarattım, Content-Type setinde application/vnd.api + json ile sorun yok – Sofia

cevap

6

Sizin POST tanımında asJSON kullanıyorsunuz. documentation about request headers yılında notlara göre:..

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

... yani, başlıklar ayarlanır:

http ("foo") almak ("bar") asJSON eşdeğerdir

.headers(Map("Authorization" -> testApiToken, 
     "Content-Type" -> "application/vnd.api+json", 
     "Accept" -> "application/vnd.api+json"))

... (HttpHeaderValues.ApplicationJson değeri olan) "application/json" için asJSON tarafından üzerine olsun.