OCR-名片识别(V2) multipart/form-data请求方式 C#?

  • 回答 (1)
  • 关注 (0)
  • 查看 (237)
/// <summary>
        /// 发送Post请求腾讯云
        /// </summary>
        public static string SendPost(byte[] image)
        {
            var url = @"http://recognition.image.myqcloud.com/ocr/businesscard";

            try
            {
                ServicePointManager.Expect100Continue = false;
                var request = (HttpWebRequest)WebRequest.Create(url);

                //var parm = "{\"appid\":\"1251163641\",\"bucket\":\"test\",\"url_list\":[\"http://yoututest-1251966477.cossh.myqcloud.com/mingpian.jpg\"]}";
                var parm = "appid=1251163641";
                var parm1 = "image=mp.jpg";
                var bs = Encoding.UTF8.GetBytes(parm);
                var img = Encoding.UTF8.GetBytes(parm1);
                request.Method = "POST";
                request.Host = "recognition.image.myqcloud.com";
                request.ContentType = "multipart/form-data;boundary=--------------acebdf13572468";
                request.ContentLength = bs.Length + img.Length+image.Length;
                request.Headers.Add("authorization", GetSign());

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(bs, 0, bs.Length);
                    stream.Write(img, 0, img.Length);
                    stream.Write(image, 0, image.Length);
                }
                using (var wr = request.GetResponse())
                {
                    //在这里对接收到的页面内容进行处理
                    var sr = new StreamReader(wr.GetResponseStream(), Encoding.UTF8);
                    string postContent = sr.ReadToEnd();
                    sr.ReadToEnd();
                    sr.Close();
                    return postContent;
                }
            }
            catch (WebException we)
            {
                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    using (var s = we.Response.GetResponseStream())
                    {
                        var reader = new StreamReader(s, Encoding.UTF8);
                        string postContent = reader.ReadToEnd();
                        return postContent;
                    }
                }
                else
                {
                    throw we;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        
        
        提交中是提示 找不到 appid  谁知道为什么啊, sdk没有C#版本的 所以只能自己写post请求  使用 json的就没问题
用户1671339用户1671339提问于
麻烦回答于
推荐
var parm = "appid=1251163641";

这个参数在哪里写到 request里面的?

可能回答问题的人

  • Superbeet

    5 粉丝0 提问0 回答
  • 腾讯云AI中心

    腾讯云 · 产品经理 (已认证)

    66 粉丝0 提问19 回答
  • 莫烦

    4 粉丝0 提问0 回答
  • 晏栋栋栋

    3 粉丝0 提问1 回答
  • daiye

    2 粉丝0 提问0 回答
  • DJ213

    1 粉丝0 提问0 回答

扫码关注云+社区

领取腾讯云代金券