为什么可以';我不能在Android中将XML数据上传到OneDrive文件中吗?

为什么可以';我不能在Android中将XML数据上传到OneDrive文件中吗?,android,xml,onedrive,Android,Xml,Onedrive,我一直在尝试使用Android应用程序将包含用户配置文件的XML数据上传到我的OneDrive帐户 无论我在互联网上找到什么样的示例代码,我的应用程序都不会上传任何数据。理想情况下,我希望我的代码尽可能简单(我仍然非常缺乏经验),但如果不为OneDrive安装插件和SDK包,可能根本无法实现这一点?还有其他文件托管服务(谷歌硬盘、Drop Box等)可以使用这种简单的代码吗?提前谢谢 我尝试使用的代码如下: import android.os.AsyncTask; import

我一直在尝试使用Android应用程序将包含用户配置文件的XML数据上传到我的OneDrive帐户

无论我在互联网上找到什么样的示例代码,我的应用程序都不会上传任何数据。理想情况下,我希望我的代码尽可能简单(我仍然非常缺乏经验),但如果不为OneDrive安装插件和SDK包,可能根本无法实现这一点?还有其他文件托管服务(谷歌硬盘、Drop Box等)可以使用这种简单的代码吗?提前谢谢

我尝试使用的代码如下:

    import android.os.AsyncTask;
    import android.widget.TextView;
    import org.xmlpull.v1.XmlPullParserException;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.text.ParseException;
    import java.util.Scanner;


    public class UploadProfileTask extends AsyncTask<String, Void, String> {

private TextView textView;
public UploadProfileTask(TextView textView) {
    this.textView = textView;
}

@Override
protected String doInBackground(String... urls) {
    try {
        return uploadUrl(urls[0]);
    } catch (XmlPullParserException e) {
        return "Xml error. URL may be invalid.";
    } catch (IOException e) {
        return "Connection error. URL may be invalid.";
    } catch (ParseException e) {
        return "Parse error. URL may be invalid.";
    }
}

@Override
protected void onPostExecute(String result) {
    textView.setText(result);
}


private String uploadUrl(String urlString) throws IOException, XmlPullParserException, ParseException {

    try{
        URL url = new URL(urlString);
        // Get the user profile as an XML string.
        String param = Globals.SerializeProfile;
        HttpURLConnection conn =(HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");

        conn.setFixedLengthStreamingMode(param.getBytes().length);
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        PrintWriter out = new PrintWriter(conn.getOutputStream());
        out.print(param);
        out.close();

        String response= "";

        Scanner inStream = new Scanner(conn.getInputStream());

        while(inStream.hasNextLine())
            response+=(inStream.nextLine());

    }
    catch(MalformedURLException ex){
    }
    catch(IOException ex){
    }

    return "Profile uploaded successfully";

}
导入android.os.AsyncTask;
导入android.widget.TextView;
导入org.xmlpull.v1.XmlPullParserException;
导入java.io.IOException;
导入java.io.PrintWriter;
导入java.net.HttpURLConnection;
导入java.net.MalformedURLException;
导入java.net.URL;
导入java.text.ParseException;
导入java.util.Scanner;
公共类UploadProfileTask扩展了AsyncTask{
私有文本视图文本视图;
公共上载配置文件任务(TextView TextView){
this.textView=textView;
}
@凌驾
受保护的字符串doInBackground(字符串…URL){
试一试{
返回上传URL(URL[0]);
}catch(XMLPullParseRexE){
return“Xml错误。URL可能无效。”;
}捕获(IOE异常){
return“连接错误。URL可能无效。”;
}捕获(解析异常){
return“解析错误。URL可能无效。”;
}
}
@凌驾
受保护的void onPostExecute(字符串结果){
setText(结果);
}
私有字符串上传URL(字符串urlString)引发IOException、XmlPullParserException、ParseException{
试一试{
URL=新URL(URL字符串);
//以XML字符串形式获取用户配置文件。
字符串参数=Globals.profile;
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
连接设置输出(真);
conn.setRequestMethod(“POST”);
conn.setFixedLengthStreamingMode(param.getBytes().length);
conn.setRequestProperty(“内容类型”、“应用程序/x-www-form-urlencoded”);
PrintWriter out=新的PrintWriter(conn.getOutputStream());
打印输出(参数);
out.close();
字符串响应=”;
Scanner inStream=新扫描仪(连接getInputStream());
while(inStream.hasNextLine())
响应+=(inStream.nextLine());
}
捕获(格式错误){
}
捕获(IOEX异常){
}
返回“档案上传成功”;
}

}

如果有错误,请粘贴。似乎没有任何错误,只是没有上传数据。