2014-03-05 19 views
1

場景: - 林執行負載測試中使用API​​的的JMeter - 從響應提取的會話ID,並將它傳遞下一個request.Request與迴應是在JSON

HTTP請求1

我登錄使用http://cabhound.com:1000/v2/driver/login和我下面的響應

{"statusCode":200,"statusMessage":"Success","errorMessage":"","responseData":{"id":0,"userName":"[email protected]","firstName":"Partner","lastName":"Tarento","phoneNumber":"2641148625","email":"[email protected]","password":"","addressOne":"","addressTwo":"","city":"","state":"","zipCode":"","loginCount":156,"welcome":"","smsOptIn":false,"promoCode":"","userNotification":"","errorMessage":"","message":"","sessionId":"6063tnerLt3013951671120oDse18492930#2","osType":"","osVersion":"","deviceType":"","deviceId":"","latitude":"","longitude":"","timeZone":"","appVersion":"","company":"Tarento","licenceNumber":"","vehicleType":"","vehicleFeature":null,"subscriptionType":"unlimited","driverWorkingCity":"Bangalore","vehicleNumber":"","locationUpdateTime":20,"rate":0,"reliable":0,"distance":0.0,"eta":0,"latitudeLongitude":"","status":"ON","payment":{"paymentType":"","cardNumber":"","cvnNumber":"","expDate":""},"vehicleTypeList":["Sedan","Limousine","SUV/Wagon","Minivan","Other"],"vehicleFeatureList":["Navigation System","Eco Friendly","Handicap accessible","Accepts credit cards"],"driverId":582,"currentLocation":null,"companyCode":"tarento","acceptanceRate":0,"like":0,"profileIndicator":0,"payWithCabHound":false,"smsSupport":false,"paymentInfo":false,"geoInfo":"","active":true}} 

請參見上述響應會話ID,這是我希望在明年的http請求數據時使用

HTTP請求2

http://cabhound.com:1000/v2/driver/dutyStatus

下面是我需要發佈的數據,在這裏我想用HTTP請求的會話ID 1

{"status":"ON","sessionId":"1311tnerLt9013956793297oDse462783#2","longitude":"77.686700","userName":"[email protected]","latitude":"12.934487"} 

如何通過HTTP的會話ID請求1(響應)HTTP請求2張貼數據

幫助我在這裏面我已經strucked

回答

0

我可以看到上述問題的解決方案2,

  1. 使用正則表達式提取器的值(我還沒有和JSON響應使用它,但我認爲這將工作)
  2. 使用BeanShell的預處理程序或後處理程序中,你可以獲取響應並使用substr或json解析器查找所需的sessionID或使用簡單的java代碼。提取所需的值並在下一次請求中使用它。
+0

您是否有任何步驟,因爲我不擅長編碼 – Sreenivas

+0

for Regex請參閱jmeter help,對於beanshell您可以參考http:// blazemeter。 com/blog/queen-jmeters-built-componentshow-use-beanshell或http://capacitas.wordpress.com/2012/10/31/using-the-power-of-java-programming-in-your-jmeter- scripts-beanshell/ –

1

我會建議使用通過JMeter PluginJSON Path Extractor可用(你需要用額外設置利布斯。

正則表達式是頭痛的發展,特別是對可以是多JSON數據。BeanShell中具有已知的性能問題,所以使用插件是最好的選擇

你的sessionId相關JSON路徑查詢會看:

$.responseData.sessionId 

Parsing JSON使用XPath Extractor in JMeter指南瞭解更多詳細信息和XPath到JSON路徑映射

+0

使用JSON路徑提取器我已經解壓sessionId並存儲在SessionCH.Now中,我必須將它傳遞到下一個Http請求 - 我試圖像這樣傳遞{「status」:「ON」,$ {SessionCH}, 「longitude」:「77.686700」,「userName」:「[email protected]」,「緯度」:「12.934487」}但它拋出錯誤 – Sreenivas

相關問題