我现在想在Android客户端向.net 服务端发送一段json,然后接收一段xml数据 发送代码如下
- Java code
public static InputStream postFromHttpClient(String path, Map<String, String> params, String encode) throws Exception { // 用于存放请求参数 List<NameValuePair> formparams = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : params.entrySet()) { formparams.add(new BasicNameValuePair(entry.getKey(), entry .getValue())); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, encode); HttpPost httppost = new HttpPost(path); System.out.println(entity.toString()); httppost.setEntity(entity); // 看作是浏览器 HttpClient httpclient = new DefaultHttpClient(); // 发送post请求 HttpResponse response = httpclient.execute(httppost); // return readStream(response.getEntity().getContent()); System.out.println(response.getEntity().getContent()); return response.getEntity().getContent(); }
这是我在网上找的一个方法,
我想返回一输入流对象,
因为我对这块儿不太熟悉,以前我都是用HttpURLConnection访问的,我想各位看看这个方法是不是可以正常发送一段json格式的字符串,如果不行,该怎么改,怎么判断我是否发送成功??
我的访问的地址是http://172.26.4.31:3515/AndroidService.svc
访问的时候还会报06-08 01:54:23.484: E/ConnectTool(401): java.lang.IllegalArgumentException: Illegal character in scheme at index 0: http://172.26.4.31:3515/AndroidService.svc
这是什么意思???
------解决方案--------------------
已经解决!