Web服务返回null [英] Web services returning null

查看:159
本文介绍了Web服务返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的PC上运行了一个良好的Web服务,并在android上运行了一个应用程序来调用它,并且应该返回一个字符串.它在我的PC上的浏览器上工作正常,但在android上返回null.我尝试了2个示例,但都返回了null,并且在监视它时,它们与Web服务无关.
两者均不干扰Web服务,并且均返回null.

试用1.

I have a good web service running on my pc and an application on android just to call it and it is suppose to return a string. it works fine on the browser on my pc, but on the android it is returning null. I tried 2 examples and both returning null, and they are not interracting with the web service, as I am monitoring it.
both not interracting with the web service and both returning null.

Trial 1.

String line = null;
	 
	try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("Valid url");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
Displaymsg(line);
	}
	catch(Exception ex)
	{
		Displaymsg(ex.getMessage());
	}




试用2.




Trial 2.

try {
         HttpClient httpclient = new DefaultHttpClient();
         HttpPost post = new HttpPost("Valid url");
         
         HttpResponse response = httpclient.execute(post);
         HttpEntity entity = response.getEntity();
         Returned = EntityUtils.toString(entity);
         Toast.makeText(this, Returned, Toast.LENGTH_LONG).show();
       } catch ( IOException ioe ) {
        ioe.printStackTrace();
       }




有什么帮助吗?

更新:也许是因为它使用蜂窝操作系统?我读过它需要asynctask扩展,但是我找不到一个很好的例子来帮助我.




Any help pls?

update: is it maybe because it uses honeycomb os? i''ve read it needs an asynctask extend but i can''t find a good example to help me. Any one maybe used it before?

推荐答案

是否也在Android网络浏览器中返回null?我认为您需要在托管该服务的PC上打开端口.通常关闭端口以接收传入消息.您可以在Google上搜索Windows版本的位置和方式.

祝你好运!
Is it also returning null in the android web browser? I think you need to open the port on your pc that is hosting the service. Ports are normally closed for incoming messages. You can search google on where and how to do that for your windows version.

Good luck!


这篇关于Web服务返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆