469,575 Members | 1,206 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

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

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
Feb 20 '08 #1
1 1866
va*****@chariot.net.au wrote:
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-jsonwould 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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Feb 23 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Luke Matuszewski | last post: by
2 posts views Thread by Kevin Newman | last post: by
1 post views Thread by Red Daly | last post: by
5 posts views Thread by Otto Wyss | last post: by
6 posts views Thread by dd | last post: by
23 posts views Thread by dhtmlkitchen | last post: by
9 posts views Thread by Jon Paal [MSMD] | last post: by
Kelicula
3 posts views Thread by Kelicula | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.