Hello,
I need to test an API by creating a JSON to send as the body. When I create a JSON string to be inserted in the Request through setBodycontent, everything looks ok:
def deleteme = "asd"
def newJson = "{"name":"${deleteme}","surname":"${deleteme}","remember_me":0}";
println(newJson);
// {"name":"${asd}","surname":"asd","remember_me":0} <--- OK
def newJson = '{"name":"${deleteme}","surname":"${deleteme}","remember_me":0}';
println(newJson);
//{"name":"${deleteme}","surname":"${deleteme}","remember_me":0} <--- OK
def createPersonRequest = (RequestObject)findTestObject('CreatePersonPost')
createPersonRequest.setHttpHeaderProperties(authHeaders)
createPersonRequest.setBodyContent(newHttpTextBodyContent(newPersonJson,"UTF-8", "application/json"))
def createPersonJSON = WS.sendRequest(createPersonRequest)
println(createPersonJSON.responseText);
But the endpoint keeps giving me a request error. Looking at the server log, the endpoint receives the body message with underscores in spite of spaces and backslashes before (some) quotes:
//{"{\"name\":_\"asd\",_\"surname\":_\"asd\",__\"remember_me\":_0}": null }
//{"{\"name\":\"${_______deleteme}\",\"surname\":\"${deleteme}\",\"remember_me\":0}": null}
What am I doing wrong?
Thanks in advance