收藏
回答

您好!我想从asp.net core webapi 调用ocr.printedText,又没有参考?

我调的时候总是返回{"errcode":41005,"errmsg":"media data missing hint: [icaJuA08392347]"

回答关注问题邀请回答
收藏

2 个回答

  • xy
    xy
    2020-07-17
    string boundary = "--------------------------" + DateTime.Now.Ticks.ToString("x");
    string boundaryH = "------------------------" + DateTime.Now.Ticks.ToString("x");
    var formData = new MultipartFormDataContent(boundary);
    var contentSend = new StreamContent(flstream);
    	
    contentSend.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
    {
    	  Name = $"\"{contentName}\"",
    	  FileName = $"\"{filename}\""
     };
    	
    contentSend.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
    
    //改写Content-Type
    contentSend.Headers.Remove("Content-Type");
    contentSend.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundaryH);
    var boundaryA = formData.Headers.ContentType.Parameters.First(o => o.Name == "boundary");//关键代码
    boundaryA.Value = boundaryA.Value.Replace("\"", String.Empty);
    formData.Add(contentSend);
    	
    	            var clientToCall = new HttpClient(/* _proxy */);
    	            var token = await _accessTonkenService._GetAccessToken();
    var response = await clientToCall.PostAsync($"http://api.weixin.qq.com/cv/ocr/comm?access_token={token.access_token}" , formData);
    
    2020-07-17
    有用 1
    回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2020-05-29

    你好,麻烦提供下appid,具体的请求,请求时间

    2020-05-29
    有用
    回复 2
    • xy
      xy
      2020-05-29
      谢谢,解决了,问题出在http请求头部的boundary参数值上
      .net core web api的类HttpClient生成的boundary如下:
      第一个图片
      但是微信平台需要的格式是如下:
      第二个图片
      发出请求前把boundary值的双引号删掉即可
      2020-05-29
      1
      回复
    • yq
      yq
      2020-06-03
      您好,能否安排下 https://developers.weixin.qq.com/community/develop/doc/0008aeb5070978c31a7a79b3e56800
      2020-06-03
      回复
登录 后发表内容
问题标签