有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Android中用PHP-MySql发布数据

我想通过安卓应用程序在PHP MySql上发布数据。当我运行应用程序时,我的应用程序会崩溃,并出现错误,如非法字符查询的IllegalArgumentException。有人能帮我吗。谢谢

这是我的密码

btnSubmitRequirment = (Button) findViewById(R.id.buttonSubmit_Order);
btnSubmitRequirment.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        strCustomerName = etCustomerName.getText().toString();
        strCustomerContact = etCustomerContact.getText().toString();
        strCurrentDate = "10-09-2014";
        System.out.println("strCurrentDate  = " + strCurrentDate);
        strProductQuantity = etProductQuantity.getText().toString().trim();
        strProductDeliveryDate = etProductDeliveryDate.getText().toString().trim();
        new SubmitOrder().execute();
    }

});

private class SubmitOrder extends AsyncTask<String, String, String> {
    /**
     * Before starting background thread Show Progress Dialog
     */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Customer_Order_Detail.this);
        pDialog.setMessage("Creating Order..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... str) {
        // TODO Auto-generated method stub

        String locationurl = "http://192.168.1.102/client_vendor_mgmt/order_insert.php?order_qty=strProductQuantity&order_delivery_date=strProductDeliveryDate&order_date=strCurrentDate&cust_name=strCustomerName&cust_contact=strCustomerContact&product_name=strSelected_Product";

        String url = locationurl.replaceAll(" ", "%20");
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);

        try {
            HttpResponse response = httpclient.execute(httppost);

            StatusLine statusLine = response.getStatusLine();
            System.out.println("new respos " + statusLine.getStatusCode() + " " + statusLine.toString());

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } // process execption }
        catch (IOException e) {
            e.printStackTrace();
        } // process execption }
        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done
        pDialog.dismiss();
        Log.d("Data Post", " Successfully !!!");
    }
}

enter image description here


共 (2) 个答案

  1. # 1 楼答案

    用这个,也用这个

    String locationurl="http://192.168.1.102/client_vendor_mgmt/order_insert.php?order_qty=4&order_delivery_date=9-12-2014&order_date=10-09-2014&cust_name=prathit &cust_contact=326457&product_name=KINGSTON 8 GB";
    
    String url=locationurl.replaceAll(" ","%20");
        HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);
    
                try {
    
                    HttpResponse response = httpclient.execute(httppost);
    
                    StatusLine statusLine = response.getStatusLine();
                    System.out.println("new respos "
                            + statusLine.getStatusCode() + " "
                            + statusLine.toString());
    
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                }// process execption }
                catch (IOException e) {
                    e.printStackTrace();
                }// process execption }
    
  2. # 2 楼答案

    url的参数中有空格字符。例如,索引137告诉您的日志。您也可以在日志中看到空格。只需向右滚动即可。在发送之前,在参数字符串上使用URLEncode.encode()。但第一个空间看起来并不是有意的