How to send the json data in GET request thru browser/Postman? - java

I need to send the json object in get request. I installed chrome Postman extension but i am not getting how can i send json object in GET request ?
Postman provides the way to send json data in Post request by adding the header as application/json and then add the json data under raw form.
How to send the json data in GET request ? Do i need to append it in URL ?

It's bad solution to send any objects using get request. But you can send it as a url parameter using url encoding:
String url = "http://example.com/query?json=" + URLEncoder.encode(json, "UTF-8");

In POSTMAN you can send body data in GET request. If you try to append in the URL using url encoding you will get error.
Try to convert json object into string and send it in the URL parameters and see if it works.
Also if your backend server allows only to send data as URL parameters and your URL is long (i.e approx 2048 characters) then I am not sure whether this will work.
If above solution doesn't work then I think you can achieve this using curl. CURL is a tool for doing all sorts of URL manipulations and transfers. You can generate cURL code using Postman. Here is the reference

You can use google chrome Postman Extension
it allows you to send and see any type of data.

Related

I am getting 400 Bad Request for ReST call only in internet explorer

In our running application, one of GET request starts giving response as 400 Bad Request in Internet Explorer.
On investigating , I found that GET request doesn't have queryParameters what were expected by ReST call.
As it is giving response in another browsers like Chrome, Mozilla,
how can I proceed further ?
this is Request currently being triggered--
Method of request is GET
https://XXXXXXXXX/XXX/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX?{%22numRecords%22:1000,%22start%22:0}&_=1487576597960
and queryParameters in #QueryParam expected by ReST api are-
-numRecords
-start
I know by the above GET request, numRecords and start will not get captured by api backend.
So , is there any chance, if my GET request lack of any #QueryParam will lead to 400 Bad request response.
I found that GET request doesn't have queryParameters
You can use query parameters in GET requests as you've provided in your example like this: http://host?queryParam1=value1. however it's not possible to pass a request body as you can do for POST or PUT requests to provide JSON encoded data for example. You can work around this by adding the JSON AND URL encoded payload to a query parameter. But you endpoint explicitely has to be able to read this parameter. So you should add this parameter to your definiotn like in this example for JAX-RS:
#GET
#Path("my-endpoint")
public String request(
#PathParam("payload") JsonObject payload
) {
What you've tried is to simply pass the payload data without specifing the name of the request parameter.
Hope this helps.

Create a HTTP GET request which sends JSON data in body with Scala?

I am having a problem when i integrate API of our partner. They always use Json data in body of HTTP request for both "POST" and "GET" method.
I'm using scalaj library for creating HTTP request but it can not send json data in Body for GET request. when i put json data to body, the Method will change to POST automatically.
I also tried to use default HttpUrlConnection in Java, but it have same problem. When i call setDoOutput method, HttpUrlConnection will change Method to POST.
How can I solve this problem in Scala?

Extracting Information from client request

How to extract url parameters in java.
Example request url: http://172.20.178.22:8080?deviceId="xxxxxxxxxxxxxxxxxxxx"
Server side i need to extract deviceId xxxxxxxxxxxxxxxxxxx as it is in JAVA.
You are putting the deviceId param value in quotes, removes the quotes it doesn't work in url
Make your request URL as below:
request url: http://172.20.178.22:8080?deviceId=xxxxxxxxxxxxxxxxxxxx
Use the below code.. should work for you
request.getParameter("deviceId")

Reading Jira Webhook POST data

I am trying to read Jira issue data using a webhook that posts the data to my servlet.
When I travserve the request parameters map, I don't find anything in it.
But the content lenght shows as "8876" which means webhook is sending the data. Somehow I am not able to read/retrieve the data in my servlet.
Also checked, content-type returns as "application/json".
Does anyone know how to read Jira webhook post data?
You have to read the response body, not the parameters map. For that purpose you can use
request.getInputStream();
or
request.getReader();
method.
PS: You can configure the web hook to post data to http://requestb.in/ so you can easily analyze the request parameters, the request body, the headers, etc.

Content length is 0 in http post response in resin 3.0

I have a client who is posting some data to our server with http POST method. Our server is resin 3.0 with java. When I send response whether data is saved or not the the content length of the response is not set. client is using curl library(php wrapper over it) and they are receiving content length as 0. When I try to submit a form through a browser to our server on the same url it works and response is shown.
I tried using Apache HttpClient to submit data through postmethod and I received content length as -1 but i did get the full response. I'm not able to understand where is the problem. Also I did some google and found that resin do some chunked encoding while sending the response. But i guess it does this also for GET method. But for GET method my client is getting the content length and is able to get the response as well. Need help with this.
"Content-Length" is a header in the response, which warns the client on how big the response will be. It is not the actual length of the stream.
You can set it's value with response.setContentLength(...); in your Servlet.

Categories

Resources