2011-06-24 21 views
0

AndroidアプリケーションをJavaで作成しようとしていますが、他のPOST情報と一緒にXMLを送信する必要があります
文字列にXMLが含まれていない場合、 XMLのみXMLのためのPOST-キーが装着されている内容ではなくAndroidからXML to 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-情報を送信しています含まれている誰もが私が間違っているの何、私に言うことはできますか?

Content-Typeまたは?

XMLをエスケープして別のXML文字列内で使用することもできますが、PHPでXML(およびXML-tags)を認識させたくない場合は、デプスペクティブにしてください(

)。

答えて

0

私は今、代わりにHttpsUrlConnectionHttpPostを使用することを選びだしてきた、そしてそれは私が投稿file_get_contents('php://input')
PHPの機能と一緒に仕事をしているようですこの投稿はここにあるので、他の人がそれに問題がある、この投稿を見ることができます

0

は、私はあなたのContentTypeをあるべき推測するアプリケーション/ RSS + xmlの

Grの

+0

私は他のポスト情報を持っているとき、それはXMLではありませんか? – The87Boy

+0

それはトリックをしなかった:( – The87Boy

関連する問題