0
public void callService()
    {  
        HttpPost postMethod = new HttpPost(url);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("latitude",latitude));
        nameValuePairs.add(new BasicNameValuePair("longitude",longitude));
        try {
            postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        DefaultHttpClient hc = new DefaultHttpClient();

        HttpResponse response = null;
        try {
            response = hc.execute(postMethod);  // not able to execute the statement.
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        HttpEntity entity = response.getEntity();

        if (entity != null) 
        {
                InputStream inStream = null;
                try {
                    inStream = entity.getContent();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                result= convertStreamToString(inStream);
                Log.i("---------------- Result",result);
        }
    } // end callService() 

我们正在尝试从我的 android 设备调用 WCF Rest 服务,上面是相同的代码,我发现代码在代码中的此语句之后终止:response = hc.execute(postMethod); 在这方面的任何帮助都将受到高度赞赏。提前致谢。

4

1 回答 1

0

根据您的帖子标题:

您是否将 POST 发送到仅允许 GET 的 REST 服务?

于 2012-04-19T21:54:20.907 回答