By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,385 Members | 847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,385 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.