我正在尝试连接到 localhost/myfile.php
在我的电脑上。 PHP文件将数据库数据转换为JSON
我想在连接后解析它。当我尝试连接时,我得到 p>
Target host must not be null, or set in parameters. scheme=null, host=null,
path=10.0.0.9/myfile.php
有什么想法吗?
public void getData(){
String result = "";
InputStream isr = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("10.0.0.9/myfile.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
}
catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
resultView.setText("Couldnt connect to database" + e);
最佳答案
您似乎缺少 URI 方案。
尝试使用 new HttpPost("http://10.0.0.9/myfile.php");
关于java.lang.IllegalStateException 连接到数据库的目标主机不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23748233/