0
我正嘗試使用android手機將圖像上傳到外部MS SQL數據庫。我正在使用Java HttpClient將字節數組發送到Web服務器或網頁。我不知道我該如何處理這個問題。網頁應該在ASP.net中。我對ASP.Net相當陌生。我對如何使用ASP.Net讀取字節數組進行了深入研究,但仍然沒有答案。我希望我的網頁或服務器讀取字節並將它們存儲到數據庫中。如何讓ASP.Net網頁從Java Android客戶端讀取字節?
下面是我想用來發送字節的Java函數(尚未經過測試,因爲我還沒有讀取字節的方法)。但我不知道如何在網站上閱讀它們。任何建議,將不勝感激。如果你們看到我做錯了事情,如果你讓我知道並告訴我應該如何解決這個問題,我們將不勝感激。請具體說明一下,因爲我真的很陌生,對網頁也不太瞭解。謝謝。
private void sendImagesToServer() throws Exception
{
ImageItem image;
HttpURLConnection conn = null;
ImageIterator iterator;
DataOutputStream dos;
byte[] byteArray;
iterator = new ImageIterator(imageAdapter);
String uploadUrl;
while(iterator.hasNext())
{
image = iterator.getNext();
Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(image.id));
Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byteArray = stream.toByteArray();
uploadUrl = "http://localhost:63776/SQLScript.aspx";
// Send request
try {
// Configure connection
URL url = new URL(uploadUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("PUT");
conn.setRequestProperty("Connection", "Keep-Alive");
dos = new DataOutputStream(conn.getOutputStream());
dos.write(byteArray, 0, byteArray.length);
dos.flush();
dos.close();
// Read response
try {
if (conn.getResponseCode() == 200) {
Toast.makeText(this,"Yay, We Got 200 as Response Code",Toast.LENGTH_SHORT).show();
}
} catch (IOException ioex) {
ioex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} finally{
}
}
}
ASP.Net是否自動調用processRequest或如何調用該函數?我如何知道即時獲得請求? – 2012-04-24 18:41:20
嗯,我想我可能不得不回到舊的TCP/IP – 2012-04-24 22:10:34