question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Send JSON body in a PUT request using nGrinder's Groovy APIs.

See original GitHub issue

Hi Team

I am usgin groovy to write nGrinder script. My APIS accept JSON payload as request body and the available options for PUT call, as mentioned in official doument, are :

1. PUT(java.lang.String uri) 
2. PUT(java.lang.String uri, byte[] data) 
3. PUT(java.lang.String uri, byte[] data, NVPair[] headers) 
4. PUT(java.lang.String uri, java.io.InputStream inputStream) 
5. PUT(java.lang.String uri, java.io.InputStream inputStream, NVPair[] headers)

Resource: http://grinder.sourceforge.net/g3/script-javadoc/net/grinder/plugin/http/HTTPRequest.html

As you can see that, there is no method accepting either JSONObject or String as a request body.Only ByteArray and InputStreams are the valid ones.

So how to make a PUT call for an API with JSON as a request body ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
GwonGisoocommented, Jan 2, 2017

Use code below:

// Set header to json
List<NVPair> headerList = new ArrayList<NVPair>()
headerList.add(new NVPair("Content-Type", "application/json"))
headers = headerList.toArray()
request.setHeaders(headers)

def reqBody = "{id:'123',value:123}";
request.POST("http://you_api_url", reqBody.getBytes())
0reactions
junoyooncommented, Jan 29, 2021

Do not post any question here. Use discussion

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngrinder-user-en - Send JSON body in a PUT request. - Nabble
Hi I want to send JSON as request body for my PUT call. But there doesn't seem to be any method accepting JSON...
Read more >
How to do a POST request with JSON via Groovy? [duplicate]
Regarding a working JSON example, the following sends a JSON body in a POST request and parses back the response, which will be...
Read more >
How to send PUT Request in Rest Assured - REST API Testing
How to implement a PUT Request using Rest Assured? Create JSON data using Simple JSON library. Send JSON content in the body of...
Read more >
Rest Assured And Be Rest Assured - Pyware
ContentTypeContentTypeJSON REST Assured also supports mapping a request project and save body mental and inch a Java object using Jackson Gson or. In...
Read more >
Vert.x Core Manual
But here's a cool bit - we don't force you to use the Java API directly from ... APIs then you need a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found