我是android新手,我正在创建一个将JSON对象发送到服务器的简单应用程序。我在互联网上找到的很多例子都有以下三行代码:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(prepai.host22.com/LoadStory.php);
HttpResponse httpResponse = httpClient.execute(httpPost);
我尝试运行它们但是当执行execute()函数时,在eclipse模拟器中运行的应用程序崩溃了。我得到了这个日志:
Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=prepai.host22.com/LoadStory.php
如何为主机提供值?我还必须在一个单独的线程中进行所有通信吗?或者还有什么我需要做的吗?
答案 0 :(得分:1)
您应该将完整的URL(包括http或https)作为字符串传递,例如:
HttpPost httpPost = new HttpPost("http://prepai.host22.com/LoadStory.php");