首页 > 解决方案 > 如何传递 byte[] 数据并从客户端获取响应?

问题描述

我有字节 [] 数据和代码形式的图像,用于传递字节数据以获取客户端的响应。我需要帮助把它们放在一起

我尝试在我有字节数据的地方使用代码,但是异步操作造成了很多混乱

"data" 包含 byte[] 数据

  private async void InitializeVideoFeedModule()
        {
            //Must in UI thread
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                //Raw data and decoded data listener
                if (videoParser == null)
                {
                    videoParser = new DJIVideoParser.Parser();
                    videoParser.Initialize( delegate (byte[] data)
                    {
                        return DJISDKManager.Instance.VideoFeeder.ParseAssitantDecodingInfo(0, data);

                    });
                }
             }
         }

传递字节数据并获得响应的代码

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Prediction-Key", "XXXXX");

// Prediction URL - replace this example URL with valid Prediction URL.
string sequenceURL = "https://abc/dcr/xyz";
HttpResponseMessage response;

using (var content = new ByteArrayContent(data))
{
   content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
   response = await client.PostAsync(sequenceURL, content);
  var output = await response.Content.ReadAsStringAsync();
   Console.WriteLine(output);

   JObject json = JObject.Parse(output);

}

当我一起使用委托对象和异步操作时,它们会导致冲突。

标签: c#.nethttpresponse

解决方案


推荐阅读