• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

curl POST not working for REST application!

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am trying to call the Spring REST application's POST call with the below curl commands.
>curl -v --request POST --data @postdata.txt http://localhost:8080/spring-rest-service/contact.json --header "Content-Type:application/json"

>curl -v --request POST --data '{"id":1,"firstName":"John","lastName":"Santosh"}' --header "Content-Type: application/json" http://localhost:8080/spring-rest-service/contact.json

Both commands are exactly same except specifying the json data in file for first command. 1st command is working fine but later is not!!! Later command is giving the below error:

* Adding handle: conn: 0xccae58
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0xccae58) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /spring-rest-service/contact.json HTTP/1.1
> User-Agent: curl/7.32.0
> Host: localhost:8080
> Accept: */*
> Content-Type: application/json
> Content-Length: 40
>
* upload completely sent off: 40 out of 40 bytes
< HTTP/1.1 400 Bad Request
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=utf-8
< Content-Length: 968
< Date: Sun, 08 Sep 2013 14:34:49 GMT
< Connection: close
<
<html><head><title>Apache Tomcat/6.0.36 - Error report</title><style><!--H1 {font-family:T
ahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-fami
ly:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-
family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:T
ahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,
sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color :
black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="
1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>de
scription</b> <u>The request sent by the client was syntactically incorrect.</u></p><HR si
ze="1" noshade="noshade"><h3>Apache Tomcat/6.0.36</h3></body></html>* Closing connection 0

The data in the postdta.txt is as below:
{"id":1,"firstName":"John","lastName":"Santosh1"}


Please let me know if you can help.

Thanks.
 
Vicky Bansal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind. It worked with the below format:

curl -v --request POST --data {\"id\":7,\"firstName\":\"me\",\"lastName\":\"Santosh\"} --header "Content-Type: application/json" http://localhost:8080/spring-rest-service/contact.json


Thanks.
 
Vicky Bansal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more doubt I have is... the below comand is returning the output in xml. I am using HttpMessageConverters without declaring in the spring context file. Using spring 3.2 version.
The doubt is, why the below command is returning xml output? It can return in json also? How it will be determined? As I have said, I have not declared anything in spring context file.

curl -v http://localhost:8080/spring-rest-service/contact



controller method is mentioned below and here also, I haven't mentioned anything like xml or json.



Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic