你可以發表你的文件低谷HTTP POST
public String sendFilePost(String urlServer, String pathToOurFile){
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
DataInputStream inputStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
try
{
FileInputStream fileInputStream = new FileInputStream(new File(pathToOurFile));
URL url = new URL(urlServer);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// Responses from the server (code and message)
String serverResponseMessage = connection.getResponseMessage();
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
}
String rrrr = response.toString();
rd.close();
fileInputStream.close();
outputStream.flush();
outputStream.close();
return rrrr;
}
catch (Exception ex)
{
return "Something went wrong!";
}
}
稍等片刻。你在談論ASP.NET MVC 3和WCF數據服務。至少你已經在你的問題中使用了這些標籤。哪些應該從客戶端(Android)應用程序接收圖像?一旦收到服務器上的圖像,你想怎麼做? ASP.NET MVC 3應用程序和WCF數據服務之間的關係是什麼? –
好吧,我可以使用任何這些,而不是在同一時間,也是一個休息的Web服務,我忘了提及。是不是我想要同時使用它們,只是使用它們中的任何一個,因爲這些是我們在這裏需要的。還要補充一點,我想要做的就是接收從Android設備上傳的圖片並將其保存到服務器上的一個文件夾中,只要 – DeX03