所以,我不能擺脫這個問題:我需要上傳一個XML
文件和.jpg
文件從我的Android應用程序(API 8)到HTTP服務器(勝利2008服務器與IIS 7.5)。我已經啓用PUT
動詞,並根據以前的搜索建議卸載WebDav
& webdav方法。 另外,我不知道我做的是正確的服務器端,因爲我無法得到任何迴應。如何使用HTTPUrlConnection urlConnection.setRequestMethod(「PUT」)上傳文件;或HttpPut?
這裏是我的代碼
URL fileurl = new URL("Server Upload Path");
HttpURLConnection urlConnection = (HttpURLConnection) fileurl
.openConnection();
urlConnection.setRequestMethod("PUT");
urlConnection.setDoOutput(true);
urlConnection.connect();
OutputStream os = urlConnection.getOutputStream();
File upFile = new File("My Local File");
//I'm sure the file exists
FileInputStream fis = new FileInputStream(upFile);
BufferedInputStream bfis = new BufferedInputStream(fis);
byte[] buffer = new byte[1024];
int bufferLength = 0;
// now, read through the input buffer and write the contents to the
// file
while ((bufferLength = bfis.read(buffer)) > 0) {
os.write(buffer, 0, bufferLength);
}
很抱歉,如果我忘了一些信息,您可能需要幫助。我對android和IIS
也是新手。
首先測試你的服務器端,並確保它的工作,甚至不擔心客戶端直到你可以驗證。使用命令行中的curl或hurl.it:http://www.hurl.it/等。 –