2011-06-24 42 views
0

我试图在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标签)(或者它会是什么字词?)它

回答

0

现在我已经选择使用HttpPost,而不是HttpsUrlConnection,这似乎与PHP的功能一起做的工作file_get_contents('php://input')
我发布这个帖子在这里,所以可以看看这篇文章

0

我猜你的ContentType应该是application/RSS + XML

的Gr

+0

另外,当我有其他邮政信息,这不是XML? – The87Boy

+0

它没有做的窍门:( – The87Boy