首页 > 代码库 > aliexpress 上传图
aliexpress 上传图
首先,图片转化为字节流 public byte[] ImagefileToByte(string srcImagePath) { System.IO.MemoryStream m = new System.IO.MemoryStream(); System.Drawing.Bitmap bp = new System.Drawing.Bitmap(srcImagePath); bp.Save(m,System.Drawing.Imaging.ImageFormat.Jpeg); byte[] ImageByte = m.GetBuffer(); return ImageByte; }最外层调用的方法 public string postUploadImage(string ImagePath) { string fileName = System.IO.Path.GetFileName(ImagePath); byte[] fileDatas = upImg.ImagefileToByte(ImagePath); Stream stream = new MemoryStream(fileDatas); string uploadImageResult = CreatePostHttpRespone(uploadImageUrl, stream, "application/octet-stream"); return uploadImageResult; //uploadImageUrl=http://gw.api.alibaba.com/openapi/param2/1/aliexpress.open/api.uploadImage/自己店铺的appkey?fileName=aa.jpg&_aop_signature=签名 } public string CreatePostHttpRespone(string url,Stream stream,string contentType) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url) ; request.Method = "POST"; request.Accept = "*/*"; request.KeepAlive = true; request.ContentType = contentType; request.Credentials = System.Net.CredentialCache.DefaultCredentials; request.ContentLength = stream.Length; using (Stream requestStream = request.GetRequestStream()) { //将内存流数据读取位置归零 stream.Position = 0; byte[] tempBuffer = new byte[stream.Length]; stream.Read(tempBuffer, 0, tempBuffer.Length); stream.Close(); //将内存流中的buffer写入到请求写入流 requestStream.Write(tempBuffer, 0, tempBuffer.Length); requestStream.Close(); //获取到上传请求的响应 WebResponse response = request.GetResponse(); //获取到上传返回的数据 //string html = GetResponseString(response); StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); string content = reader.ReadToEnd(); response.Close(); request = null; return content; } }
aliexpress 上传图
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。