0
我想調用restFullAPI,我使用asp.net webapi創建,我可以看到結果來自web瀏覽器,但我不能從java調用它以編程方式 這裏是我的java客戶端代碼:無法在Android或控制檯中從java調用RestFull API
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) {
}
}
響應值是:
HTTP/1.1 405不允許的方法[緩存控制:無緩存,附註: 無緩存,允許:GET,內容類型:應用/ JSON;字符集= UTF-8, 過期:-1,服務器:IIS/10.0,X-ASPNET-版本:4.0.30319, X-SourceFiles:???? = UTF-8乙YzpcdXNlcnNcYWRtaW5pc3RyYXRvclxkb2N1bWVudHNcdmlzdWFsIHN0dWRpbyAyMDE1XFByb2plY3RzXEFwcGFzZWNcQXBwYXNlY1xhcGlcZ2V0XDE = =, X-已啓動方式:ASP.NET,日期:孫老師,2016年9月18日6點31分52秒GMT, 的Content-Length:73]