Android 无法从服务器读取XML文件

Android 无法从服务器读取XML文件,android,Android,我正在从服务器读取XML文件。我面临的问题是,我已经将urlconnection方法设置为set,但在调试时,我检查了它,该方法是POST and duw,我的inputstream.read()函数将返回-1。所以编译器无法从服务器读取文件 我从服务器读取文件的代码如下: urlString="some url"; URL url = new URL(urlString); HttpURLConnection urlConnec

我正在从服务器读取XML文件。我面临的问题是,我已经将urlconnection方法设置为set,但在调试时,我检查了它,该方法是POST and duw,我的inputstream.read()函数将返回-1。所以编译器无法从服务器读取文件

我从服务器读取文件的代码如下:

urlString="some url";

                URL url = new URL(urlString);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

                urlConnection.setRequestMethod("GET");
                urlConnection.setDoOutput(true);

                //connect
                urlConnection.connect();

                File SDCardRoot = Environment.getExternalStorageDirectory();
                //create a new file, to save the downloaded file
                File file = new File(SDCardRoot,"prahova.GIS");

                FileOutputStream fileOutput = new FileOutputStream(file);

                //Stream used for reading the data from the internet
                InputStream inputStream = urlConnection.getInputStream();

                //this is the total size of the file which we are downloading
                totalSize = urlConnection.getContentLength();

                //create a buffer...
                byte[] buffer = new byte[1024];
                int bufferLength = 0;

                while ( (bufferLength = inputStream.read()) > 0 )
                {
                    fileOutput.write(buffer, 0, bufferLength);
                   downloadedSize += bufferLength;
                }

                fileOutput.close();

你收到错误了吗?我没有收到错误,但我也没有收到任何文件。你能显示传递给HttpUrlConnection的真实Url吗?我建议记录输入流返回的内容,这样你就可以查看它是在读取问题还是在写入文件