我的Android应用程序中有一个函数,它将一个长字符串发送到PHP文件,然后将其插入数据库。 现在,我的问题是,PHP文件永远不会从我的应用程序中获取整个字符串。
如果我将其作为Http参数发送,是否可能缩短我的字符串?或者你有什么想法可能有错吗?
(我很抱歉我的英语不好,我不是母语人士)
我的Java代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://********/********/Map/addMarkers.php");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
try {
nameValuePairs.add(new BasicNameValuePair("marker",
Functions.ObjToString(spM[i].getMarkerToSave()+"")));
nameValuePairs.add(new BasicNameValuePair("database",database[spM[i].getType()]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.d("Marker als String ",Functions.ObjToString(spM[i].getMarkerToSave())+"");
Log.d("Database",database[spM[i].getType()]);
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = in.readLine()) != null) {
Log.d("Antwort des Servers: ",line);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
我的PHP代码:
<?php
$db = @new mysqli('XXXXXXX', 'dbXXXXX', 'XXXX', 'dbXXXXX');
if (mysqli_connect_errno()) {
die('Konnte keine Verbindung zur Datenbank aufbauen: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}
$marker_toString = $_POST["marker"];
$db_name= $_POST["database"];
$sql = "INSERT INTO $db_name (marker_toString) VALUES ('$marker_toString')";
echo "marker: $marker_toString";
echo "db: $db_name";
$eintragen = mysqli_query($db, $sql);
&GT;
Antwort des Servers:
日志文件:
Marker als String r000ACXNyAC9jb20uxweansmsdfpiwenfefnwiwnfepwnfpn .......
数据库park_markers
Antwort des Servers:marker:rO0ABXQAClNrYXRlLVNob3A = db: ****
答案 0 :(得分:0)
您正在对您的名称值对进行网址编码。可能你必须在php端解码它们。