簡體   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