You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Ken Burcham <ke...@gmail.com> on 2009/11/20 05:16:36 UTC

getting a json response from a curl post

Hi everyone,

With the following curl command:

  curl -i -H "Accept: application/json" -X POST -d "name=Andrew" -u  
admin:admin http://localhost:8888/content/amiamo/thing/

I'm hoping to get a json representation of the newly minted "thing"  
but alas, I get html back instead:

HTTP/1.1 201 Created
Location: /amiamo/thing/andrew
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Server: Jetty(6.1.x)

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed  
with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License,  
Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  
implied.
    See the License for the specific language governing permissions and
    limitations under the License.
  -->
<html>
<head>
     <title>Content created /content/amiamo/thing/andrew</title>
</head>
     <body>
     <h1>Content created /content/amiamo/thing/andrew</h1>
     <table>
         <tbody>
             <tr>
                 <td>Status</td>
                 <td><div id="Status">201</div></td>
             </tr>
             <tr>
                 <td>Message</td>
                 <td><div id="Message">Created</div></td>
             </tr>
             <tr>
                 <td>Location</td>
                 <td><a href="/amiamo/thing/andrew" id="Location">/ 
amiamo/thing/andrew</a></td>
             </tr>
             <tr>
                 <td>Parent Location</td>
                 <td><a href="/amiamo/thing" id="ParentLocation">/ 
amiamo/thing</a></td>
             </tr>
             <tr>
                 <td>Path</td>
                 <td><div id="Path">/content/amiamo/thing/andrew</ 
div></td>
             </tr>
             <tr>
                 <td>Referer</td>
                 <td><a href="" id="Referer"></a></td>
             </tr>
             <tr>
                 <td>ChangeLog</td>
                 <td><div id="ChangeLog"><pre>created("/content/amiamo/ 
thing/andrew");<br/>modified("/content/amiamo/thing/andrew/name");<br/ 
 ></pre></div></td>
             </tr>
         </tbody>
     </table>
     <p><a href="">Go Back</a></p>
     <p><a href="/amiamo/thing/andrew">Modified Resource</a></p>
     <p><a href="/amiamo/thing">Parent of Modified Resource</a></p>
     </body>


What I'm really after is the Location and the id that sling assigned  
and I suppose I could use regex and pull out what I want, but it seems  
like it should be honoring the "accepts" header and give me back  
json...  Or maybe I'm thinking about it all wrong?

Thanks!

ken.



Re: getting a json response from a curl post

Posted by Christophe Lombart <ch...@gmail.com>.
The current implementation of the default POST returns always an HTML
response.
You have to write your own servlet or script to return a json response.

Just one question to the dev team : The default GET can return different
kind of response (HTML, JSON, XML). Why not to do the same for a POST ?

Christophe


2009/11/20 Ken Burcham <ke...@gmail.com>

> Hi everyone,
>
> With the following curl command:
>
>  curl -i -H "Accept: application/json" -X POST -d "name=Andrew" -u
> admin:admin http://localhost:8888/content/amiamo/thing/
>
> I'm hoping to get a json representation of the newly minted "thing" but
> alas, I get html back instead:
>
> HTTP/1.1 201 Created
> Location: /amiamo/thing/andrew
> Content-Type: text/html; charset=utf-8
> Transfer-Encoding: chunked
> Server: Jetty(6.1.x)
>
> <!--
>   Licensed to the Apache Software Foundation (ASF) under one or more
>   contributor license agreements.  See the NOTICE file distributed with
>   this work for additional information regarding copyright ownership.
>   The ASF licenses this file to You under the Apache License, Version 2.0
>   (the "License"); you may not use this file except in compliance with
>   the License.  You may obtain a copy of the License at
>
>        http://www.apache.org/licenses/LICENSE-2.0
>
>   Unless required by applicable law or agreed to in writing, software
>   distributed under the License is distributed on an "AS IS" BASIS,
>   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>   See the License for the specific language governing permissions and
>   limitations under the License.
>  -->
> <html>
> <head>
>    <title>Content created /content/amiamo/thing/andrew</title>
> </head>
>    <body>
>    <h1>Content created /content/amiamo/thing/andrew</h1>
>    <table>
>        <tbody>
>            <tr>
>                <td>Status</td>
>                <td><div id="Status">201</div></td>
>            </tr>
>            <tr>
>                <td>Message</td>
>                <td><div id="Message">Created</div></td>
>            </tr>
>            <tr>
>                <td>Location</td>
>                <td><a href="/amiamo/thing/andrew"
> id="Location">/amiamo/thing/andrew</a></td>
>            </tr>
>            <tr>
>                <td>Parent Location</td>
>                <td><a href="/amiamo/thing"
> id="ParentLocation">/amiamo/thing</a></td>
>            </tr>
>            <tr>
>                <td>Path</td>
>                <td><div id="Path">/content/amiamo/thing/andrew</div></td>
>            </tr>
>            <tr>
>                <td>Referer</td>
>                <td><a href="" id="Referer"></a></td>
>            </tr>
>            <tr>
>                <td>ChangeLog</td>
>                <td><div
> id="ChangeLog"><pre>created("/content/amiamo/thing/andrew");<br/>modified("/content/amiamo/thing/andrew/name");<br/></pre></div></td>
>            </tr>
>        </tbody>
>    </table>
>    <p><a href="">Go Back</a></p>
>    <p><a href="/amiamo/thing/andrew">Modified Resource</a></p>
>    <p><a href="/amiamo/thing">Parent of Modified Resource</a></p>
>    </body>
>
>
> What I'm really after is the Location and the id that sling assigned and I
> suppose I could use regex and pull out what I want, but it seems like it
> should be honoring the "accepts" header and give me back json...  Or maybe
> I'm thinking about it all wrong?
>
> Thanks!
>
> ken.
>
>
>