解决方法
您可以创建一个Rest Webservice,这里是一个
tutorial,您可以使用URI传递输入数据,您应该计划您的URI应该如何发布客户名称:
[OperationContract] [WebInvoke(Method = "POST",ResponseFormat = Webmessageformat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate = "json/post-customer/{name}")] void postCustomer(string name);
使用客户ID获取客户数据:
[OperationContract] [WebInvoke(Method = "GET",UriTemplate = "json/get-customer/{id}")] Customer getCustomer(string id);
然后在托管您的web服务后,您需要使用HTTP客户端从您的Android应用程序访问它,例如:
String uri = "uri to your service"; HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); ResponseHandler<String> handler = new BasicResponseHandler(); String result = null; try { result = httpclient.execute(request,handler); } catch (ClientProtocolException e) { e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } httpclient.getConnectionManager().shutdown();
之后你应该在“result”中有一个字符串,这个字符串代表你的响应(json或xml).
希望这些信息可以帮到你.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。