Sending a JSON object to a web app function via Http?

V

valheru

Hi,

I'm not sure if this question even makes sense, so bear with me here.

I'm using a tool called HtmlUnit (which is like JUnit) to send a http
request to my web application. The http address needs to include JSON
objects because the JavaScript/Java functions at the web application
are expecting to receive them as parameters.

Let me clarify:

suppose the web app servlet has a (Java) function:

boolean myfunction(JSONObject myobject)

and I want to call it from an outside test using Html, how do I do
this?

I want to send a request like "http://localhost/json/<path>/
myfunction" and then put the JSON object stuff at the end of the http
line so that the function myfunction accepts it as the parameter
myobject.

How do I do this? Can it be done? Is this "the way" to send such
objects to such functions?

Thanks for your help. Any info would be appreciated.

Mark Spezzano
 
T

Thomas 'PointedEars' Lahn

suppose the web app servlet has a (Java) function:

boolean myfunction(JSONObject myobject)

Irrelevant. Java is not JavaScript.
and I want to call it from an outside test using Html, how do I do
this?

I want to send a request like "http://localhost/json/<path>/
myfunction" and then put the JSON object stuff at the end of the http
line so that the function myfunction accepts it as the parameter
myobject.

How do I do this?

You would need to encode the path component so that the URI complies
with RFC 3986, and a server that supports either the PATHINFO feature (with
which foo/<encoded-json> would be possible) or append the encoded as the
query part after the `?' character (foo?[name=]<encoded-json>).

In ECMAScript implementations this can be achieved by using the return value
of the encodeURIComponent() method, and that of escape() as a fallback.
Can it be done?
Yes.

Is this "the way" to send such objects to such functions?

The usual approach is to use a POST request instead, for the URI length is
not limited per default, but it is in Internet Explorer, to 2083 characters.
Thanks for your help. Any info would be appreciated.

HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top