0
votes

I want to call restFullAPI that I Create with asp.net webapi , I can see Result From web browser but I cant Call it from java Programmatically here is my java Client Code :

public static void main(String[] args){

        try
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = null;




            String url = "http://localhost:16083/api/get/1";



            httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
                    CookiePolicy.RFC_2109);

            httpPost = new HttpPost(url);
            HttpResponse response = httpClient.execute(httpPost);


            HttpEntity entity = response.getEntity();

            // A Simple JSON Response Read
            InputStream instream;
            try {
                instream = entity.getContent();

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


        }

    }

the response value is :

HTTP/1.1 405 Method Not Allowed [Cache-Control: no-cache, Pragma: no-cache, Allow: GET, Content-Type: application/json; charset=utf-8, Expires: -1, Server: Microsoft-IIS/10.0, X-AspNet-Version: 4.0.30319, X-SourceFiles: =?UTF-8?B?YzpcdXNlcnNcYWRtaW5pc3RyYXRvclxkb2N1bWVudHNcdmlzdWFsIHN0dWRpbyAyMDE1XFByb2plY3RzXEFwcGFzZWNcQXBwYXNlY1xhcGlcZ2V0XDE=?=, X-Powered-By: ASP.NET, Date: Sun, 18 Sep 2016 06:31:52 GMT, Content-Length: 73]

1

1 Answers

0
votes

Like the error says the method you're using (post) is not allowed. Do a get instead.