为什么HttpClient.execute返回null?

时间:2016-10-05 04:47:01

标签: java httpclient httpcontext cisco

以下是我的代码段:

private HttpClient httpClient;
private CookieStore APICookieStore;
private HttpHost targetHost;
private AuthCache authCache;
private CredentialsProvider credentialsProvider;

httpClient = HttpClients.createDefault();
nxAPICookieStore = new BasicCookieStore();
targetHost = new HttpHost(swtch.getHostIP(), 80, "http");
authCache = new BasicAuthCache();
authCache.put(targetHost, new BasicScheme());
credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
    new UsernamePasswordCredentials(swtch.getUserName(), swtch.getPassword()));
HttpPost post = new HttpPost("/ins");
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credentialsProvider);
context.setAuthCache(authCache);
context.setCookieStore(APICookieStore);
// JSON command that needs to be sent across
StringEntity postBody = new StringEntity(parsedString,"UTF-8");
post.setEntity(postBody);
// Execute send and receive to remote switch
JsonNode returnNode = httpClient.execute(targetHost, post, this, context);

parsedString

{ "ins_api" : { "version" : "1.0", "type": "cli_conf", "chunk": "0", "sid": "1", "input": "show clock", "output_format": "json" } }

我不确定这里缺少什么;所有数据似乎都是正确的,但returnNode的值为:null

0 个答案:

没有答案