2016-12-19 7 views
0

maven WebアプリケーションでJDBC経由でSQLデータベースに接続しています。私は安らかなAPIを作成しました。javaクライアントで@POSTリクエストを使用してパラメータを送信する

私も私のURIエントリ・ポイントに接続し、URIが何のparams例えばを持っていない場合、私は成功したクライアントを介してデータを返すことができ、出力

を返すJavaクライアントを持っています.../users/getAll

サーバのPOSTメソッドにパラメータを渡す際に問題が発生します。

Serverコード

@POST 
@Path("/NewUser") 
@Produces(MediaType.APPLICATION_JSON) 
public List<String> CreateUser(@HeaderParam("Name")String name,@HeaderParam("Email")String email) 
{ 
    if(name.equals("")||email.equals("")) 
      return null; 
    else return BankingService.CreateUser(name, email); 
} 

クライアントコード

 WebResource webResource = client.resource(url); 

     String input = "{\"name\":tom,\"email\":\"[email protected]\"}"; 

     ClientResponse response = webResource.type("application/json") 
       .post(ClientResponse.class, input); 

     String output = response.getEntity(String.class); 
     System.out.println(output); 

私は、文字列入力で、間違ってパラメータを渡すについて行くことができますか? データがDB/ に入力されていないため、アドバイスをいただければ幸いです。

答えて

1

以下のフォーマットを試してください。

String input = "{\"name\":\"tom\",\"email\":\"[email protected]\"}"; 

ClientResponse response = webResource.type("application/json") 
     .post(ClientResponse.class, input); 
関連する問題