Search code examples
httpgroovyresponse

How to get the Only success (200 ok) Response from Http Request Using Groovy script


Here i'm Facing problem with groovy script that.Want to extract the response data from the http request.When the Response data consisting of 200 as value then only extract that value_description and print value. So here is the response what i am getting

{"value":"200","value_description":"pass"}

and code is

def response = new groovy.json.JsonSlurper().parse("200".equals(prev.getResponseData()))

means is there any possible that if value is 200 and than only print value description.using groovy script please tell me with simple code.


Solution

  • Not sure if this is what you mean, it's really hard to tell, but I think you mean:

    import groovy.json.JsonSlurper
    
    def response = new groovy.json.JsonSlurper().parseText(prev.responseData)
    if (response.value == '200') {
        println response.value_description
    }