Send JSON body in a PUT request.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Send JSON body in a PUT request.

rachit
Hi
I want to send JSON as request body for my PUT call.
But there doesn't seem to be any method accepting JSON or String.
So what about the APIs accepting body as application/json.

BR
Rachit
Reply | Threaded
Open this post in threaded view
|

Re: Send JSON body in a PUT request.

qing
I send json body in a POST request.
request1.setHeaders(headers)
post_data=(
        NVPair( "xxxx",yyyy),
        NVPair( "xxxx",yyyy),
        NVPair( "xxxx", yyyy),
        NVPair( "xxxx", yyyy),
        NVPair( "xxxx",yyyy),
        NVPair( "xxxx", yyyy),
        NVPair( "xxxx", yyyy),
        NVPair( "xxxx", yyyy),
        )
result = request1.POST("xxxx",post_data)

hoping this help
Reply | Threaded
Open this post in threaded view
|

Re: Send JSON body in a PUT request.

rachit
Hi qing

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.

Best Regards
Rachit

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