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); 在此背景下的任何帮助将受到高度赞赏。 提前谢谢。
答案 0 :(得分:0)
根据您帖子的标题:
您是否向仅允许GET的REST服务发送POST?