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'

安卓代码:

        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 :

  • 文件名 = 文件名
  • fileContent = 以 base64 编码的文件内容

在您的 asp 文件中,只需获取 2 个参数内容,进行 base 64 解码,并将其写入名为 filename 参数的文件中...

于 2012-06-19T09:48:56.613 回答