上传图片

//随手拍图片
                string url = "http://localhost:8099/OpenAPI/UpLoadPhotographImage";
                string imgresult = "";
                List<string> imglist = new List<string>();
                foreach (imglist item in img)
                {
                    string img1 = item.imgurl;
                    if (img1 != null && img1.Length > 0)
                    {
                        WebRequest request = System.Net.WebRequest.Create(url);

                        request.Method = "POST";
                        request.ContentType = "application/x-www-form-urlencoded";

                        Stream reqStream = request.GetRequestStream();
                        string img1base64 = System.Web.HttpUtility.UrlEncode(img1);
                        Encoding encoding = Encoding.GetEncoding("utf-8");
                        byte[] postdata = encoding.GetBytes("img1base64=" + img1base64);
                        reqStream.Write(postdata, 0, postdata.Length);
                        reqStream.Close();

                        HttpWebResponse myResponse = (HttpWebResponse) request.GetResponse();
                        StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("gb2312"));
                        imgresult = reader.ReadToEnd();//得到结果
                        imglist.Add(imgresult);
                    }
                }
                Service_Photoes pEntity = new Service_Photoes();
                if (imglist.Count > 0)
                {
                    pEntity.ServiceOrderId = OrderCode;
                    pEntity.ImageUrl = imglist[0];
                    pEntity.FileName = "服务";
                    pEntity.ThumbnailUrl100 = imglist[0];
                    pEntity.ThumbnailUrl160 = imglist[0];
                    pEntity.ThumbnailUrl180 = imglist[0];
                    pEntity.ThumbnailUrl220 = imglist[0];
                    pEntity.ThumbnailUrl310 = imglist[0];
                    pEntity.ThumbnailUrl40 = imglist[0];
                    pEntity.ThumbnailUrl410 = imglist[0];
                    pEntity.ThumbnailUrl60 = imglist[0];
                    //pEntity.ImageUrl2 = imglist.Count > 1 ? imglist[1] : "";
                    //pEntity.ImageUrl3 = imglist.Count > 2 ? imglist[2] : "";
                    //pEntity.ImageUrl4 = imglist.Count > 3 ? imglist[3] : "";
                    //pEntity.ImageUrl5 = imglist.Count > 4 ? imglist[4] : "";
                }

                Service_OrderBll orderBll = new Service_OrderBll();
                Service_PhotoesBll photoesBll = new Service_PhotoesBll();
                bool bRet = orderBll.SubmitService(entity);
                if (pEntity.ImageUrl != "")
                {
                    photoesBll.SubmitPhotograph(pEntity);
                }

posted @ 2019-12-17 19:16  lnnlern  Views(104)  Comments(0Edit  收藏  举报