0

以下のエラーが表示されます。

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など)

誰でもこの問題について私に提案できますか?

4

1 に答える 1

0

あなたができることは、2つのパラメータを url に送信することです:

  • fileName = ファイル名
  • fileContent = base64 でエンコードされたファイルのコンテンツ

asp ファイルで、2 つのパラメーターのコンテンツを取得し、base 64 デコードを行い、ファイル名パラメーターとして名前が付けられたファイルに書き込むだけです...

于 2012-06-19T09:48:56.613 に答える