我試圖在Java中創建一個Android應用程序,並且我需要將XML與其他某些POST信息一起發送
它適用,當String不包含XML時,包含了什麼,我做錯了XML只針對XML的POST-鍵連接,而不是內容Android將XML發送到PHP頁面
我使用下面的代碼
// Check if there is nothing to input
if (input == null)
input = new HashMap<String, String>();
// Add the mobile's ID
input.put("MobileID", ((TelephonyManager)cxt.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
// The string for the input
String strInput = "";
// For each input
for (Entry<String, String> ent : input.entrySet()) {
// Check if the string is not empty
if (strInput.length() > 0)
strInput += "&";
// Add to the String
strInput += URLEncoder.encode(ent.getKey(), Encoding.UTF_8.name()) + "=" + URLEncoder.encode(ent.getValue(), Encoding.UTF_8.name());
}
// Open the connection and setup default values
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setRequestMethod("POST");
// Set the RequestProperties
conn.setRequestProperty("Authorization", "Basic " + CtrSettings.getInstance().getAuthentication());
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", strInput.getBytes().length + "");
// Set the booleans for the connection
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
// Create the input
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
dos.write(strInput.getBytes());
dos.flush();
dos.close();
// Return the connection
return conn;
可有人告訴我發送POST信息,?
我錯過了關於內容類型或?
另一種方法可能是轉義XML以在另一個XML字符串中使用,但我不希望PHP在我退化之前將其識別爲XML(和XML標籤)(或者它會是什麼字詞?)它
另外,當我有其他郵政信息,這不是XML? – The87Boy
它沒有做的竅門:( – The87Boy