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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • valheru@chariot.net.au

    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(JSON Object 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
  • Thomas 'PointedEars' Lahn

    #2
    Re: Sending a JSON object to a web app function via Http?

    valheru@chariot .net.au wrote:
    suppose the web app servlet has a (Java) function:
    >
    boolean myfunction(JSON Object 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 encodeURICompon ent() 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 bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Comment

    Working...