HTTP 发布不执行


HTTP Post is not executed

我正在尝试使用 HTTP 的 Post 方法上传 Base64 字符串,这是我的代码:

public void upload_signature(){
        final DBHelper db = new DBHelper(et);
        ArrayList<HashMap<String, String>> array_list = new ArrayList<HashMap<String, String>>();
        array_list = db.getSignatures(ticket);
        Log.i("Num Sig", "" + array_list.size());
        for(int i = 0; i < array_list.size(); i++){
            final String chaka = array_list.get(i).get("signature");
            final SharedPreferences prefs = EnterTotals.this.getSharedPreferences("-", MODE_PRIVATE);
            /**
            HttpClient Client = new DefaultHttpClient();
            String URL = "http://hs.ha.com/api/RetrieveDispatch.php?action=add_signature="
                    + "&hs_customer=" + prefs.getInt("hs_customer", 1) + "&ticket=" + ticket + "&signature_path=" + chaka;
            HttpGet httpget = new HttpGet(URL);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            if(isAvailable()) {
                try {
                    String result = Client.execute(httpget, responseHandler);
                    Log.i("info", result + " " + URL);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            */
            Thread thread = new Thread(new Runnable(){
                @Override
                public void run() {
                    HttpParams httpParams = new BasicHttpParams();
                    HttpConnectionParams.setConnectionTimeout(httpParams, 60000);  //1 min
                    HttpConnectionParams.setSoTimeout(httpParams, 60000);          //1 min
                    HttpClient client = new DefaultHttpClient(httpParams);
                    HttpPost post = new HttpPost("http://hs.ha.com/api/RetrieveDispatch.php");
                    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                    pairs.add(new BasicNameValuePair("action", "add_signature"));
                    pairs.add(new BasicNameValuePair("signature_path", chaka));
                    pairs.add(new BasicNameValuePair("hs_customer", "" + prefs.getInt("hs_customer", 1)));
                    pairs.add(new BasicNameValuePair("ticket", "" + ticket));
                    try {
                        post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));   // as UTF-8
                        HttpResponse response = client.execute(post);
                        HttpEntity ent = response.getEntity();
                        String text = EntityUtils.toString(ent);
                        Log.i("RESPONSE SIGNATURE: ", "" + text);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    } catch (ClientProtocolException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            thread.start();

        }
    }

当我尝试使用 GET 方法时,我收到请求 URI 太长的错误。所以我把它评论掉了。但是当我转向 POST 方法时,我认为它从未执行过,因为我看不到标签响应签名。

我不知道出了什么问题。

更新的 PHP 代码:

  <?php
require_once("../includes/common.php");
$action = trim($_POST['action']);
if($action == "get_num_rows"){
$hs_customer = trim($_POST['hs_customer']);
    $ticket = trim($_POST['ticket']);
    $signature_path = trim($_POST['signature_path']);
    $sql = "INSERT INTO jsa_signatures SET hs_customer = '$hs_customer', ticket = '$ticket', signature_path = '$signature_path'";
    mysql_query($sql) or die(mysql_error());
}
?>

在 android 代码中,您通过POST方法发布参数,而在 php 中,您尝试使用GET方法检索它。我认为这是错误。

将 php 中的$_GET替换为 $_POST,它将起作用。