Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the cause of this error?

 
hani se
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
i'm new to RESTful services,i want to call a service from my java cms but i receive a http internal error, what is it's cause?how can i accept the output from server?
this is the service:
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" \
-d "title=about me&content=I live in Paris." \
http://localhost:8080/contenthub/contenthub/store
link

this is my code:


 
francesco umani
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
port 8081 indeed 8080?
 
hani se
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
francesco umani wrote:port 8081 indeed 8080?

port 8081 is for apache stanbol online demo
 
francesco umani
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using



?
 
hani se
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you get output by using this? can you show the complete code?
thanks
 
francesco umani
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String input = "title=about me&content=I live in Paris.";
 
hani se
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Francesco but i didn't understand the cause of my code's error and the difference between my code and yours?
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DataOutputStream used to format data in platform independent way, OutputStream sends just a raw binary data.
 
francesco umani
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is only the parameter "title=about me&content=I live in Paris."
in the curl example you provided:
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" \
-d "title=about me&content=I live in Paris." \

But In the code you used

String input = "i live in Paris";

so the request is not well formed.





 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
francesco umani wrote:
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" \
-d "title=about me&content=I live in Paris." \

So this is a URL-encoded values, which goes to POST-request body, and the service looks like a basic servlet, which accepts the attributes. Is that what OP have?
 
francesco umani
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, in fact:

application/x-www-form-urlencoded

This is the default content type. Forms submitted with this content type must be encoded as follows:

Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
The control names/values are listed in the order they appear in the document. The name is separated from the value by `=' and name/value pairs are separated from each other by `&'.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for a descriptive answer, francesco.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic