0
項目id_category未發送到服務器,但其他項目發送沒有問題。與POST查詢的奇怪行爲
add.php:
<?php
header("Content-Type: text/html;charset=utf-8");
require_once('../php/mysql_conect.php');
$use_db=mysql_query("use open_service;");
$date=date("Y-m-d");
$time=date("H:i:s");
$insert=mysql_query("insert into records(id_category,name,phone,device_id,address,text,publish_date,publish_time) value('$_POST[id_categoty]','$_POST[name]','$_POST[phone]','$_POST[device_id]','$_POST[address]','$_POST[text]','$date','$time');");
?>
我的代碼部分:
//獲取ID設備
*TelephonyManager telMgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String device_id = telMgr.getDeviceId().toString(); name_post = name.getText().toString(); phone_post=phone.getText().toString(); address_post=address.getText().toString(); comment_post=comment.getText().toString(); String id_category="1"; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter("http.protocol.version",
HttpVersion.HTTP_1_1); ()「,」http.socket.timeout「,新的 Integer(2000)); ()「http.getParams()。setParameter(」http.protocol.content-charset「, 」UTF-8「); HttpPost httppost = new HttpPost(「http://10.100.100.20/test/mobile/add.php」);
try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6); nameValuePairs.add(new BasicNameValuePair("name", name_post)); nameValuePairs.add(new BasicNameValuePair("phone", phone_post)); nameValuePairs.add(new BasicNameValuePair("address", address_post)); nameValuePairs.add(new BasicNameValuePair("text", comment_post)); nameValuePairs.add(new BasicNameValuePair("device_id", device_id)); nameValuePairs.add(new BasicNameValuePair("id_category", id_category));<--It's don send to
服務器 httppost.setEntity(新UrlEncodedFormEntity(namevaluepairs中, 「UTF-8」));
response = httpclient.execute(httppost); //Создаем уведомление Toast toast=Toast.makeText(getBaseContext(), "Заявка успешно отправлена", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, -200); toast.show(); //Возвращаемся а предыдущие Activity Intent intent= new Intent(); intent.setClass(getApplicationContext(), EservisActivity.class); startActivity(intent); }*
你怎麼知道它不會被髮送到服務器?如果我是你,我會仔細檢查'add.php'。 – aioobe
顯示您的PHP webservice期望從Android客戶端獲得的請求結構? –