Donavon wrote:
I agree with all of the responses that Embed perl was made to mainly use
CGI.pm and multipart/form-data and really shouldn't be used outside of that.

BUT As long as there is possibility that it might be able to receive
application/json data I have to look for a way to do it. It's part of my
job to look for solutions that work within current limitations.

If every response to this email is "It's not possible" that is something
I can take to a meeting.  If the responses are "You shouldn't or it's
difficult" then I have to keep searching for a solution that is
understandable and workable.

I'm willing to pay a small consulting fee or a donation to a charity,
for assistance in figuring this out.

So what are the suggestions for handling a call like this on a script by
script basis.  I might be possible to limit the scripts accepting these
calls to specific directories.

|varformData
={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
:"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
:formData,success:function(response){CurrentArray=response;}}); Thank
You, ~Donavon |






On 9/4/2016 2:30 AM, Michael Smith wrote:
I wouldn't use embperl to accept json.  I see embperl as being
designed for HTML output, so I don't really see how it helps when
dealing with json.

On Fri, Sep 2, 2016 at 11:43 PM, Donavon <d...@mycopanet.com
<mailto:d...@mycopanet.com>> wrote:

    Good to know that there are still some Embperl users out there.

    We have a large SAAS system mainly in Embperl, so our usage of
    Embperl is not going away anytime soon.


    My current question to the Embperl community is:

    *How to accept **application/json?*

    **I know that "Embperl uses CGI.pm internally to process forms
    encoded with multipart/form-data" and that get processed into %fdat.

    Is there a way to disable this behavior dynamically per page to
    accept application/json data.

    Thanks,
    ~Donavon

Perhaps I am misunderstanding the scenario you are dealing with, but I use json in my regular Embperl-based website all the time to communicate with the client side Javascript. On the client side I just use JSON.parse and JSON.stringify to decode/encode objects for sending via regular POST calls. And on the server side, I get that data through the usual %fdat and decode it using JSON::Parse. This is all done using the regular, vanilla Embperl GET/POST. So unless you are dealing with some other third party application that you have no control over (i.e. something is generating calls that are specifically application/json), I don't see why using JSON with Embperl is an issue. After all, JSON is really just a way of encoding objects as text, like XML.

I also generate application/xml responses using Embperl, just set $http_headers_out{'Content-type'} to whatever you are using and then make sure the actual output matches that format. What I do is have a base.epl that figures out what the current request is about (usually via a page_type() sub that is redefined in subdirectories using Embperl::Object), and then base.epl calls e.g. base_html.epl if it's a regular web page, or base_xml.epl if it's going to be an xml response, or base_text.epl if it's a simple text response etc.

Sorry, I don't know if I'm completely missing the point, but it's very easy to work with json in Embperl. Unless, like I said, you have some other application that is actually generating application/json calls, and you have no control over that, and you're trying to figure out how to get Embperl to even handle those requests... if that's the case, then ok, I'm not sure how that would work with %fdat etc.

Neil


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscr...@perl.apache.org
For additional commands, e-mail: embperl-h...@perl.apache.org

Reply via email to