2013-04-25 2 views
0

GET 요청에 잘 작동하는 Java RestfulWeb Service를 만들었습니다. 그러나 POST 요청을 수락하는 방법에 대한 좋은 리소스를 찾을 수 없습니다.Java 웹 서비스에 대한 간단한 POST 요청

이 내가 웹에서이 방법을 액세스하기 위해 난 그냥 mywebservice.com/hello/thisismyID로 이동하는 방법은 "ID"를 수신에서

@Path("/hello") 
public class Hello { 

    @GET 
    @Path(value = "/ids/{id}") 
    public String ids(@PathParam(value = "id") final String id) throws JSONException { 
     return getResults("select * from " + id); 
    } 

GET 실행하는 방법입니다.

POST로 수행해야하는 경우 어떻게 보입니까? 사전에

감사합니다,

-D

+0

사용'@ POST' 대신'의를 @ 알 겠어? –

+2

읽어보기 http://stackoverflow.com/questions/8194408/how-to-access-parameters-in-a-restful-post-method – MariuszS

답변

1

@Path("/hello") 
public class Hello { 

    @POST 
    @Path(value = "/ids") 
    public String ids(@HeaderParam("id") final String id) throws JSONException { 
     return getResults("select * from " + id); 
    } 
} 
+0

짧고 정확하며 작동합니다. 감사! –

+0

@MariuszS 해당 게시물 서비스에 전화하는 방법 URL을 나에게 알려주실 수 있습니까? – user4342532

+0

@ Sateesh2607 다음과 같이'curl -X POST -H "id = foo"http : // localhost : 8080/hello/ids' – MariuszS

1
@Path("/hello") 
public class Hello { 

    @POST 
    @Path("/ids/{id}") 
    public String ids(@PathParam("id") final String id) throws JSONException { 
     return getResults("select * from " + id); 
    } 
} 

철저한 튜토리얼은 여기에서 찾을 수 있습니다 : Vogella_REST

+1

http://stackoverflow.com/questions/8194408/how-to-access-parameters - 안식 - 휴식 - 사후 방법 – sschrass

관련 문제