簡體   English   中英

從Beanshell Jmeter運行時不包含JSON

[英]JSON not getting included when running from Beanshell Jmeter

我們有一個CURL命令,該命令基本上將運行狀態推送到儀表板。 以下是帶有虛擬URL的命令。

該命令必須將兩個信息詳細信息發送到儀表板。 info和包含內容的info Text is missingPlease check. 從任何Linux盒執行時,此curl命令都可以正確運行,並且會顯示JSON發送的信息,但是當我們嘗試從Jmeter Beanshell運行相同命令時,該命令已成功運行,但僅JSON中的信息就無法運行儀表板。

String command = "curl -X POST -d \"status=GREEN\" -d 'info={\"error\":[{\"info\":\"Text is missing\"},{\"info\":\"Please check.\"}]}' abc.com/api/run-dashboard/apikey=456655656";
    Process p = Runtime.getRuntime().exec(command);
    p.waitFor();
#to display the output-
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    StringBuilder everything = new StringBuilder();
    String line;
    while( (line = in.readLine()) != null) 
    {
      everything.append(line);
    }
    in.close();
    log.info("OUTPUT: " + everything.toString());
    }

我們嘗試在beanshell中添加額外的標頭-H "Content-Type: application/json" ,但徒勞。

有人可以讓我們知道從Beanshell發送的命令中缺少什么,為什么沒有顯示JSON數據。 shold,我們添加任何其他標頭詳細信息。

  1. 您可能需要提供curl實用程序的完整路徑,例如/usr/bin/curl
  2. 您的命令可能因某些錯誤而失敗,因此請確保處理p.getErrorStream()
  3. 請注意, 從JMeter 3.1開始,建議使用JSR223測試元素和Groovy語言進行腳本編寫 ,請考慮切換到它,因為Beanshell性能可能是一個很大的問號。 此外,您將能夠將Beanshell代碼轉換為類似以下內容的代碼:

     def response = "curl -X POST -d \\"status=GREEN\\" -d 'info={\\"error\\":[{\\"info\\":\\"Text is missing\\"},{\\"info\\":\\"Please check.\\"}]}' http://example.com/api/run-dashboard/apikey=456655656".execute().text log.info(response) 

    JMeter Groovy卷發

    更多信息: Apache Groovy-為什么以及如何使用它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM