android将数据作为xml发送到php服务器

android将数据作为xml发送到php服务器,android,Android,我有一个数据类型是字符串,我想把这个数据以xml的形式发送到服务器。我该怎么办?你们能帮我吗 httpclient = new DefaultHttpClient(); httppost = new HttpPost("http://longvansolution.tk/login.php"); // make // su

我有一个数据类型是字符串,我想把这个数据以xml的形式发送到服务器。我该怎么办?你们能帮我吗

httpclient = new DefaultHttpClient();
            httppost = new HttpPost("http://longvansolution.tk/login.php"); // make
                                                                            // sure
                                                                            // the
                                                                            // url
                                                                            // is
                                                                            // correct.
            // add your data
            nameValuePairs = new ArrayList<NameValuePair>(2);
            // Always use the same variable name for posting i.e the android
            // side variable name and php side variable name should be
            // similar,
            nameValuePairs.add(new BasicNameValuePair("username",
                    txtusername.getText().toString().trim())); // $Edittext_value
                                                                // =
                                                                // $_POST['Edittext_value'];
            nameValuePairs.add(new BasicNameValuePair("password",
                    txtpassword.getText().toString().trim()));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            // Execute HTTP Post Request
            response = httpclient.execute(httppost);
httpclient=newdefaulthttpclient();
httppost=新的httppost(“http://longvansolution.tk/login.php"); // 制作
//当然
//
//网址
//是
//对。
//添加您的数据
nameValuePairs=新的ArrayList(2);
//发布时始终使用相同的变量名,即android
//端变量名和php端变量名应为
//类似的,
添加(新的BasicNameValuePair(“用户名”),
txtusername.getText().toString().trim());//$编辑文本值
// =
//$_POST['Edittext_value'];
添加(新的BasicNameValuePair(“密码”),
txtpassword.getText().toString().trim());
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
response=httpclient.execute(httppost);
现在我不想用这种方式,我想发送xml

String url = "http://yourserver";
File file = new File(Environment.getExternalStorageDirectory(),
    "yourfile");
try {
    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost(url);

    InputStreamEntity reqEntity = new InputStreamEntity(
        new FileInputStream(file), -1);
    reqEntity.setContentType("binary/octet-stream");
    reqEntity.setChunked(true); // Send in multiple parts if needed
    httppost.setEntity(reqEntity);
    HttpResponse response = httpclient.execute(httppost);
    //Do something with response...

} catch (Exception e) {
    // show error
}
可能重复的