首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >OCR-名片识别(V2) multipart/form-data请求方式 C#?

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

提问于 2018-11-28 15:58:27
回答 1关注 0查看 691
代码语言:js
复制
/// <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的就没问题

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档