Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# android-web api发送/接收图像_C#_Android_Json_Rest_Asp.net Web Api - Fatal编程技术网

C# android-web api发送/接收图像

C# android-web api发送/接收图像,c#,android,json,rest,asp.net-web-api,C#,Android,Json,Rest,Asp.net Web Api,我相信这是一个常见的问题,我可能会找到解决办法,但我不理解。此外,我做这件事完全是盲目的。另一点是:我不想使用第三方库 我需要通过c#rest Web服务将安卓应用程序中的图像发送到服务器 我观察了将位图转换为字节[]的方法 public static byte[] getBitmapAsByteArray(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

我相信这是一个常见的问题,我可能会找到解决办法,但我不理解。此外,我做这件事完全是盲目的。另一点是:我不想使用第三方库

我需要通过c#rest Web服务将安卓应用程序中的图像发送到服务器

我观察了将位图转换为字节[]的方法

public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 0, outputStream);       
        return outputStream.toByteArray();
    }
这里我有两个(至少)问题:

  • 如何将其作为JSON发送?我使用公共和URLSAFE(或类似的)标志尝试了Base64.encode(),但在服务器端出现错误:不是有效的Base64

  • 那么我假设客户端没有问题,那么如何接收和处理字节[]?现在,它似乎试图自动转换,但失败了,可能是因为客户端发送了无效数据或。。。我不知道

  • 我现在不能提供代码(事实上我认为我根本没有代码来做这件事),但是如果需要的话,我会用我的代码来更新


    感谢并抱歉提出这个可怕的问题

    Android:

    byte[] content = getBitmapAsByteArray(bitmap);
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new ByteArrayEntity(content));           
    HttpResponse response = httpClient.execute(httpPost);
    
    c#net

    byte[] fileData = null;
    using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
    {
        fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
    }
    

    首先,谢谢你的回答。第二,Android部分,它已经被弃用了。