其余客户端协议异常

时间:2019-01-26 05:57:43

标签: rest tomcat tomcat5.5 jdk1.5 servicenow-rest-api

将jdk 1.5用于REST客户端,但面临客户端协议异常的异常。 提到了许多堆栈溢出问题,特别是enter link description here

但是无法弄清楚。 还使用了抢占式身份验证,但无法消除该错误。 下面是代码

String host = "service now host";
    String host_url = "http://servicenow/hosturl/";
    String postData = null;


    postData = "{\"caller_id\":\"CTL SWAT\","
            + "\"short_description\":\"hello678\"," + "\"cmdb_ci\":\" CLT \","
            + "\"description\":\"Testing jdk 15\","
            + "\"contact_type\":\"Phone\","
            + "\"assignment_group\":\"NA - EWH PASE - Tier 2\","
            + "\"impact\":\"4\"," + "\"urgency\":\"4\"}" + "\",";



    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(new HttpHost(host)),
            new UsernamePasswordCredentials("username", "password"));

    CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider).build();


        HttpPost httpPost = new HttpPost(host_url);
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-Type", "application/json");

        HttpEntity entity;
        try {
           entity = new ByteArrayEntity(postData.getBytes("utf-8"));
            httpPost.setEntity(entity);
            CloseableHttpResponse response = httpclient.execute(httpPost);


        } catch (UnsupportedEncodingException e) {
            System.out.println("Threading WORKING LEVEL 1 unsupported");
        }
         catch (ClientProtocolException e) {
             System.out.println("Threading WORKING LEVEL 1 clientprotocol"); 
        } catch (IOException e) {
            System.out.println("Threading WORKING LEVEL 1 ioexception"); 
        }
        finally{
            System.out.println("finnaly");
        }
使用的

jar是commons编解码器1.5,common logging 1.1.3,httpclient 4.3.3和httpcore 4.3.2 感谢您的所有评论和帮助

0 个答案:

没有答案