线程" main"中的例外情况java.lang.RuntimeException:失败:HTTP错误代码:WebserviceTest.vrn.App.main上的405(App.java:38)

时间:2016-10-13 11:28:04

标签: java web-services rest

我在使用java测试以下给定的webservice时遇到上述错误。我没有得到响应。

Webservice是http://services.groupkt.com/state/get/IND/all

我的代码是

genre

此处引发错误

try {

        // create HTTP Client
        HttpClient httpClient = HttpClientBuilder.create().build();

        // Create new getRequest with below mentioned URL
        HttpPost getRequest = new HttpPost("http://services.groupkt.com/state/get/IND/all");

        // Add additional header to getRequest which accepts application/xml data
        getRequest.addHeader("accept", "application/xml");

        // Execute your request and catch response
        HttpResponse response = httpClient.execute(getRequest);

        // Check for HTTP response code: 200 = success
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        }

        // Get-Capture Complete application/xml body response
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
        String output;
        System.out.println("============Output:============");

        // Simply iterate through XML response and show on console.
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }

0 个答案:

没有答案