繁体   English   中英

将Android与MYSQL和PHP本地主机连接

[英]Connecting android with MYSQL & PHP localhost

我是android的新手,我想使用php将我的应用程序与mysql连接,但是它不起作用,我的代码有问题吗? 请帮我:

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2:8888/jobs/mobile/home/searchJobs");

        try {

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            //add data for post
            nameValuePairs.add(new BasicNameValuePair("keywords","keyword for search" ));
            nameValuePairs.add(new BasicNameValuePair("location", "Location value"));
            //set url encoded entity
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

            HttpEntity resEntity = response.getEntity();

                String responseStr = EntityUtils.toString(resEntity).trim();
                Toast.makeText(Search_result.this, "response: "+responseStr, 1000).show();

                // you can add an if statement here and do other actions based on the response

                Log.v("tag", "Response: " +  responseStr);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }

这是错误: 在此处输入图片说明

根据您的日志,检查以下内容:

  • 检查清单中的SDK版本-编译版本/定位最新的SDK
  • 检查模拟器设置,我在这里看到了类似您的问题输出: 单击我

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM