Issue
I need to pass raw text as body without quotes in my rest assured
Sample code used:
String command = "dumpsys package com.android.chrome | grep versionName"
request.pathParam("deviceId", deviceId);
request.contentType(ContentType.TEXT).body(command);
but still it reads it as String with quotes but here I need to pass the body as below
dumpsys package com.android.chrome | grep versionName
But it is getting passed as
"dumpsys package com.android.chrome | grep versionName"
due to which I am getting failure in my case
Solution
Your body is sent without quotes. You can try with netcat
tool.
Start listening on some port (e.g. 9123
): netcat -l -p 9123
Then run the code:
String command = "dumpsys package com.android.chrome | grep versionName";
RestAssured
.given()
.baseUri("http://localhost:9123")
.basePath("/{deviceId}")
.pathParam("deviceId", 123)
.contentType(ContentType.TEXT)
.body(command)
.get();
And watch the log of netcat
:
alexey@master-host:~$ netcat -l -p 9123
GET /123 HTTP/1.1
Accept: */*
Content-Type: text/plain; charset=ISO-8859-1
Content-Length: 53
Host: 0.0.0.0:9123
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.13 (Java/11.0.20.1)
Accept-Encoding: gzip,deflate
dumpsys package com.android.chrome | grep versionName
Answered By - Alexey R. Answer Checked By - Pedro (WPSolving Volunteer)