1

our clients will sends the request using json object on our servlet on basis of that data i want to update our database.

the json object is something as follows:

{"person":{"employment":{"id":"123","department":"developer","Company":"XYZ","sal":"10000"},"fName":"ABC","mName":"PQR","lName":"XYZ","email":"[email protected]","address":"mumbai west"}

I want to test this by sending the json object on browser url directly, which contain more than 256 characters.

i tried :-

https://integration.com/details/Notification?req={"person":{"employment":{"id":"123","department":"developer","Company":"XYZ","sal":"10000"},"fName":"ABC","mName":"PQR","lName":"XYZ","email":"[email protected]","address":"mumbai west"}

But its giving me following exception :

org.codehaus.jackson.JsonParseException: Unexpected character ('o' (code 111)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: java.io.StringReader@3e3a5a9c; line: 1, column: 2] at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433) at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521) at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442) at org.codehaus.jackson.impl.ReaderBasedParser._handleUnexpectedValue(ReaderBasedParser.java:1198) at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:485) at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2770) at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718) at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863) at payment.EmaxCBNotification.doService(EmaxCBNotification.java:72) at payment.EmaxCBNotification.doGet(EmaxCBNotification.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.directi.pg.filters.ESAPITransactionFilter.doFilter(ESAPITransactionFilter.java:276) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.directi.pg.filters.UTF8Filter.doFilter(UTF8Filter.java:31) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:662)

pls help me!

Should I use the HTTP POST request, which will hit the url with above defined format on the browser?

3
  • is this a RESTful API call that they are making? Do these calls come in with any parameters? Commented Feb 25, 2015 at 8:14
  • Using more than 256 characters in a URL? What encoding are you using? Commented Feb 25, 2015 at 8:21
  • dear ha9u63ar the url is not encrypted with any encryption technique.. Commented Feb 25, 2015 at 9:03

3 Answers 3

2

Use GET to Retrieve data and PUT to Replace (update) data. Never use GET to update data - NEVER!

Representational state transfer from en.wikipedia.org

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using POST to update data, can use CURL to post the request & test

   curl -v -H "Content-Type: application/json" -X POST \
    -d '{"name":"your name","phonenumber":"111-111"}' 
   URL

It's posted well in this POST: sending a post request in a url itself

5 Comments

Dear Paul thank you for your reply, i did it for updating the database.. Yes call come with the parameters.. I face problem while sending that json object in browser..
hi SRV - so are you trying to make a browser request sending a JSON message body?
it's not possible to send a message body with a browser request. You can send request parameters.
can i use a request like written bellow? https://integration.com/details/Notification?req={"person":{"employment":{"id":"123","department":"developer","Company":"XYZ","sal":"10000"},"fName":"ABC","mName":"PQR","lName":"XYZ","email":"[email protected]","address":"mumbai west"} Because i want to read the values from the json request which are there in the url.
You can url encode the json body and try that same request. Bear in mind, in that scenario you are passing in the values as request parameters or query parameters.
0

Yes, you certainly can pass JSON in a URL Querystring. You just have to URLencode the JSON string first. As @dmn said, the data is probably better passed via POST because of GET's size restrictions.

1 Comment

Indeed, a GET request should never be used to update data. However, we might consider a need to include JSON in a GET URL in case of "search" requests, to send the search criteria as JSON. But I wonder how to handle cases like {"category":"green", "keyword":"\"hello\""} since some browsers and some webservers (such as Tomcat) replace the backslash with a slash, and/or return 400 Bad Request.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.