简体   繁体   English

在Web API上调用特定服务

[英]Calling specific service on web api

I have a web API running with a service called Authorize. 我有一个运行有名为Authorize的服务的Web API。

Authorize takes 1 parameter (called ) and returns a different key. Authorize接受1个参数(称为)并返回不同的密钥。

I'm going to call this from a Java application. 我将从Java应用程序中调用它。 I've done 我弄完了

public static void main(String[] args0)
{
    HttpClient httpClient = HttpClientBuilder.create().build();

    try{

        HttpPost request = new HttpPost("http://localhost:50481");
        StringEntity params = new StringEntity("Authorize={\"auth\":\"123456\"}");
        request.addHeader("content-type", "application/json");
        request.addHeader("Accept", "application/json");
        HttpResponse response = httpClient.execute(request);            
        JSONObject json = new JSONObject(response);

        System.out.println(json);

    }
    catch(Exception ex){
        System.out.println(ex.toString());
    }
    finally{ 

    }
}

The problem is, that the System.out.println(json); 问题是, System.out.println(json); only returns an empty object: {} 仅返回一个空对象: {}

Does that mean that there is a problem in the service itself, or that it does not hit a valid method on the API? 这是否意味着服务本身存在问题,或者未在API上找到有效方法?

由于{}是有效的(空)json,因此您不会遇到任何异常,就好像您的服务返回带有空json对象的响应一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM