2012-06-19 36 views
0

我得到下面的錯誤:從Android的上傳圖片到ASP.NET

Cannot process the message because the content type 
'multipart/form-data; 
boundary=0JxmnFLOmjvutAKrtR1bmPCqpG8M6WbwE-aAvh8' was not the expected 
type 'text/xml; charset=utf-8' 

的Android代碼:

 HttpPost httppost = new HttpPost("http://192.168.9.103/AndroidService/MediaUploadService.svc/uploadFile1"); 
     File photo = new File(Environment.getExternalStorageDirectory(), "01.jpg"); 
     MultipartEntity t = new MultipartEntity(); 
     t.addPart("t", new FileBody(photo)); 
     httppost.setEntity(t); 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpResponse response = httpclient.execute(httppost); 

WCF代碼:

public class MediaUploadService : IMediaUploadService 
{ 
    public void UploadFile(Stream fileContents) 
    { 
     byte[] buffer = new byte[10000]; 
     int bytesRead, totalBytesRead = 0; 
     do 
     { 
      bytesRead = fileContents.Read(buffer, 0, buffer.Length); 
      totalBytesRead += bytesRead; 
     } while (bytesRead > 0); 
     File.WriteAllText(@"D:\\Vechile\log2.txt", totalBytesRead.ToString()); 
    } 
} 

有人能幫我做這個過程嗎?

我的問題: -
必須從Android上傳圖片文件到服務器(通過IIS - >的.asp,的.asmx,.SVC等)

可以在任何一個建議我在這個問題上?

回答

0

的東西,你可以做的是送2個URL參數:

  • 文件名=文件名
  • fileContent =文件的內容爲Base64

在你的asp文件進行編碼,只需獲取2個參數內容,進行64位解碼,然後將其寫入名爲文件名參數的文件中...