ashx链接的图片保存

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/rush_mj/article/details/83239432

有的网页图片地址链接是http:xxxxxxxx.ashx,保存下来是个空文件。

下载方法:谷歌的network找到那个链接的地址(空白就开着网络控制台刷新一下页面),右击选择copy,copy as curl

然后在命令行里 加 -o path/filename 就行了,文件就保存好了,真是神器。谷歌连cookie都帮你搞到命令行里去了,所以不用担心账号未登录请求失败的问题。

展开阅读全文

ashx 下载

04-23

[code=csharp]<%@ WebHandler Language="C#" Class="PDF" %>rnrnusing System;rnusing System.Web;rnusing System.Diagnostics;rnusing System.IO;rnrnpublic class PDF : IHttpHandler rn public void ProcessRequest (HttpContext context) rn context.Response.ContentType = "text/plain";rn //context.Response.Write("Hello World");rn string url = context.Request["url"];rn string path = HttpContext.Current.Server.MapPath("~/PDF/");rnrn HtmlToPdf(url,path);rn rnrnrnrnrnrn [color=#FF0000] //下载信息,这里下载不了文件啊。高手指教[/color]rn FileInfo info = new FileInfo(filePath);rn long fileSize = info.Length;rn context.Response.Clear();rn context.Response.ContentType = "application/x-zip-compressed";rn context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);rn //不指明Content-Length用Flush的话不会显示下载进度 rn context.Response.AddHeader("Content-Length", fileSize.ToString());rn context.Response.TransmitFile(filePath, 0, fileSize);rn context.Response.Flush();rn context.Response.Close();rn rn rn rnrn public static bool HtmlToPdf(string url, string path)rn rn tryrn rn rn if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path))rn return false;rn Process p = new Process();rn string str = System.Web.HttpContext.Current.Server.MapPath("~/wkhtmltopdf.exe");rn string filename = path + "Artistic.pdf";rn if (!System.IO.File.Exists(str))rn return false;rn p.StartInfo.FileName = str;rn p.StartInfo.Arguments = " \"" + url + "\" " + path;rn p.StartInfo.UseShellExecute = false;rn p.StartInfo.RedirectStandardInput = true;rn p.StartInfo.RedirectStandardOutput = true;rn p.StartInfo.RedirectStandardError = true;rn p.StartInfo.CreateNoWindow = true;rn rn p.StartInfo.Arguments = string.Format(" \"0\" \"1\" --password \"2\" --username \"3\"", url, filename, "123", "admin","");rn p.Start();rn System.Threading.Thread.Sleep(100);rnrn return true;rn rn catch (Exception ex)rn rn HttpContext.Current.Response.Write(ex);rn rn return true;rn rn rn rn public bool IsReusable rn get rn return false;rn rn rnrn[/code] 论坛

silverlight与ashx

07-07

我用webclient上传文件,后台建立ashx用于保存文件,然后将文件名存入到数据库中并取得了新插入项主键id,我想返回这个id给silverlight客户端,请问该怎么做?换句话说,silverlight如何获取ashx的返回值?rnUploadHander.ashx如下:rn[code=csharp]using System;rnusing System.Collections.Generic;rnusing System.Linq;rnusing System.Web;rnusing System.IO;rnusing System.Data.SqlClient;rnusing WebGISApp.Web.General;rnrnnamespace WebGISApp.Webrnrn /// rn /// UploadHandler 的摘要说明rn /// rn public class UploadHandler : IHttpHandlerrn rnrn public void ProcessRequest(HttpContext context)rn rn string filename = Uri.UnescapeDataString(Convert.ToString(context.Request.QueryString["InputFile"]));rn string fileExtend = System.IO.Path.GetExtension(filename);rn string fid = Uri.UnescapeDataString(Convert.ToString(context.Request.QueryString["Fid"]));rn string newGuidName = "";rn string errorString = "";rn SqlConnection sqlConnection = SqlHelper.OpenSqlConnection(ref errorString);rn SqlCommand myComm = new SqlCommand();rn myComm.Connection = sqlConnection;rn SqlTransaction st = sqlConnection.BeginTransaction();rn myComm.Transaction = st;rn tryrn rn newGuidName = Guid.NewGuid().ToString() + fileExtend;rn context.Response.ContentType = "text/plain";rn context.Response.ContentEncoding = System.Text.Encoding.Unicode;rn int ids = -1;rn tryrn rn if (fid.Trim().ToUpper() != "NULL")rn rn myComm.CommandText = string.Format(XMLHelper.GetCommandString("CataLogConfig/DeleteFileInfo", "value"), fid);rn File.Delete(context.Server.MapPath("~/" + Convert.ToString(myComm.ExecuteScalar())));rn rn string strSQL = XMLHelper.GetCommandString("CataLogConfig/AddFileInfo", "value");rn myComm.CommandText = strSQL;rn myComm.Parameters.AddWithValue("@FileName", filename);rn myComm.Parameters.AddWithValue("@GuidName", "Files/" + newGuidName);rnrn //if (type.Trim() == "img")rn //rn // myComm.Parameters.AddWithValue("@Bid", bid);rn //rn //else if (type.Trim() == "doc")rn //rn // myComm.Parameters.AddWithValue("@Did", did);rn //rn ids = Convert.ToInt32(myComm.ExecuteScalar());rn st.Commit(); rn rn catchrn rn ids = -2;rn st.Rollback();rn return;rn rn finallyrn rn context.Response.Write(ids.ToString());rn rnrn using (FileStream fileStream = File.Create(context.Server.MapPath("~/Files/" + newGuidName)))rn rn byte[] bufferData = new byte[4096];rn int bytesToBeRead;rn while ((bytesToBeRead = context.Request.InputStream.Read(bufferData, 0, bufferData.Length)) != 0)rn rn fileStream.Write(bufferData, 0, bytesToBeRead);rn rn fileStream.Close();rn rn rn catchrn rn st.Rollback();rn rn finallyrn rn myComm.Dispose();rn sqlConnection.Dispose();rn rn rnrn public bool IsReusablern rn getrn rn return false;rn rnrn rn rn[/code] 论坛

没有更多推荐了,返回首页