Java Spring作为基于Akka的REST HTTP调用的客户端
我必须调用从 java-spring 用 scala-akka 项目编写的REST服务。 __
我的scala REST服务就像
val route =    post {
        path("notification" / "signUp"){
            headerValueByName("App_Key") { app_key => {
              handleWith {
                requestParameters: RequestParameters =>
                  //application specific implementation
              }
            }
            }
        }
它 包含 并在json格式中包含 。
请求参数如下:
case class RequestParameters (     var name: String,
     var email: String,
     var password: String,
     var hashKey: String
   )
所以我必须从 服务。我从java 打电话时很挣扎。
*http://ipadress:port/notification/signUp
回答:
你可以通过 以下实施:
try {            Client client = Client.create();
            WebResource webResource = client.resource(http://ipadress:port/notification/signUp);
            JSONObject formData=new JSONObject();
            formData.put("name", UserName);
            formData.put("email", EmailId);
            formData.put("password", Password);
            formData.put("urlHash",HashKey);
            ClientResponse response = webResource.header("App_Key",xxxxxxxxxxxxxxxxxxxxxxxxxx).type(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, formData);
        } catch (Exception e) {
            e.printStackTrace();
        }
以上是 Java Spring作为基于Akka的REST HTTP调用的客户端 的全部内容, 来源链接: utcz.com/qa/416599.html








