
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using EVTBT.Core; |
using EVTBT.DAL; |
using System.Data; |
using System.Threading; |
using System.IO; |
using System.Drawing; |
using System.Net; |
public partial class Default2 : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
DataTable DT = Common.NoPager2("EntCertificateInfo", "", "CertID,QualiName,QualiNO", "", "IsDel='0'").Tables[0]; |
string loaction = " F:\\FoodSafe\\"; |
foreach (DataRow DR in DT.Rows) |
{ |
//DataRow DR = DT.Rows[2]; |
try |
{ |
string sss = "http://sbcx.saic.gov.cn:9080/tmois/wszhcx_getImageInputSteremSF.xhtml?regNum=" + DR["QualiNO"].ToString() + "&intcls=5&size=5"; |
WebRequest request = WebRequest.Create(sss); |
request.Timeout = 30000; |
WebResponse response = request.GetResponse(); |
Stream reader = response.GetResponseStream(); |
byte[] buff = StreamToBytes(reader); |
if (buff.Length > 0) |
{ |
string path = Server.MapPath("~/ImgCache/" + DR["CertID"].ToString() + "/" + DR["QualiNO"].ToString() + ".jpg"); |
string path2 = Server.MapPath("~/ImgCache/" + DR["CertID"].ToString() + "/"); |
Directory.CreateDirectory(path2); |
Stream s = new FileStream(path, FileMode.Append); |
int c = 0; //实际读取的字节数 |
s.Write(buff, 0, buff.Length); |
s.Close(); |
s.Dispose(); |
Common.Insert2("adm_adminlog", "UserIP,Des,Remark", "'" + DR["CertID"].ToString() + "','" + DR["QualiNO"].ToString() + "','" + path + "'"); |
} |
reader.Close(); |
reader.Dispose(); |
response.Close(); |
} |
catch (Exception ex) |
{ |
} |
} |
} |
public static byte[] StreamToBytes(Stream stream) |
{ |
List<byte> bytes = new List<byte>(); |
int temp = stream.ReadByte(); |
while (temp != -1) |
{ |
bytes.Add((byte)temp); |
temp = stream.ReadByte(); |
} |
return bytes.ToArray(); |
} |
public Bitmap Get_img(string URL, string location, string filename) |
{ |
Bitmap img = null; |
HttpWebRequest req; |
HttpWebResponse res = null; |
try |
{ |
System.Uri httpUrl = new System.Uri(URL); |
req = (HttpWebRequest)(WebRequest.Create(httpUrl)); |
req.Timeout = 180000; //设置超时值10秒 |
req.UserAgent = "MSIE 6.0"; |
req.Accept = "image/*"; |
req.Method = "GET"; |
res = (HttpWebResponse)(req.GetResponse()); |
img = new Bitmap(res.GetResponseStream());//获取图片流 |
img.Save(@"F:/" + location + filename);//随机名 |
} |
catch (Exception ex) |
{ |
string aa = ex.Message; |
Common.Insert2("adm_adminLog", "Des", "'" + location + " " + filename + "'"); |
} |
finally |
{ |
res.Close(); |
} |
return img; |
} |
} |




中级程序员
by: 读你 发表于:2017-04-27 14:21:43 顶(0) | 踩(0) 回复
回复评论