向服务器post或者get数据返回
#region 向服务器端Get值返回
/// <summary>
/// 向服务器端Get返回
/// </summary>
///<see cref="Author">小柯</see>
/// <param name="url"></param>
/// <param name="param"></param>
/// <param name="param">GET</param>
/// <returns></returns>
public static string SendInformation(string Url, string Param, string Method = "GET")
{
if (!string.IsNullOrEmpty(Param))
{
Url = Url + "?" + Param;
}
Uri uri = new Uri(Url);
HttpWebRequest webReq = HttpWebRequest.Create(uri) as System.Net.HttpWebRequest;
webReq.Method = Method;
webReq.Headers["Cache-Control"] = "no-cache";
HttpWebResponse webResp = null;
Stream respStream = null;
StreamReader objReader = null;
try
{
webResp = (HttpWebResponse)webReq.GetResponse();
respStream = webResp.GetResponseStream();
objReader = new StreamReader(respStream, System.Text.Encoding.GetEncoding("UTF-8"));
return objReader.ReadToEnd();
}
catch (WebException ex)
{
return "无法连接到服务器/r/n错误信息:" + ex.Message;
}
finally
{
if (webResp != null)
webResp.Close();
if (respStream != null)
respStream.Close();
if (objReader != null)
objReader.Close();
}
}
#endregion #region 向服务器端post返回
/// <summary>
/// 向服务器端post返回
/// </summary>
/// <param name="url">服务器URL</param>
/// <param name="param">要发送的参数字符串</param>
/// <returns>服务器返回字符串</returns>
public static string PostInformation(string url, string param, string Method="Post")
{
System.Text.Encoding myEncode = System.Text.Encoding.GetEncoding("UTF-8");
byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(param);
HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(url);
webReq.Headers["Cache-Control"] = "no-cache";
webReq.Method = Method;
webReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
webReq.ContentLength = postBytes.Length;
Stream reqStream = null;
HttpWebResponse webResp = null;
StreamReader sr = null;
try
{
reqStream = webReq.GetRequestStream();
reqStream.Write(postBytes, , postBytes.Length);
webResp = (HttpWebResponse)webReq.GetResponse();
sr = new StreamReader(webResp.GetResponseStream(), myEncode);
return sr.ReadToEnd();
}
catch (WebException ex)
{
return "无法连接到服务器\r\n错误信息:" + ex.Message;
}
finally
{
if (reqStream != null)
reqStream.Close();
if (webResp != null)
webResp.Close();
if (sr != null)
sr.Close();
}
}
#endregion
/// <summary>
/// 远程上传图片
/// <param name="fileData">文件数据</param>
/// <param name="ImgName">文件名</param>
/// <param name="ImgPath">图片放的文件路径</param>
public static bool RemoteUpload(byte[] fileData, string ImgName, string ImgPath)
{
try
{
string _CustomEncryption = CustomEncryption();
if (fileData.Length == ) return false;
if (string.IsNullOrEmpty(ImgPath)) { ImgPath = "/Upload/User/" + PublicFun.MemberID(); }
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri(System.Configuration.ConfigurationManager.AppSettings["Resource_Url"] + "/Programs/MyGallery/UploadImg.ashx?CustomEncryption=" + _CustomEncryption + "&ImgName=" + ImgName + "&ImgPath=" + ImgPath)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
string htmlcode = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
if (htmlcode == "上传成功!")
{
return true;
}
else
{
return false;
} }
catch (Exception ex)
{
throw new Exception("文件上传失败", ex.InnerException);
}
}
/// <summary>
/// 远程上传图片
/// </summary>
/// <param name="fileData">文件数据</param>
/// <param name="ImgName">文件名</param>
/// <param name="UploadUrl">服务器地址</param>
/// <param name="Width">要求图片的宽</param>
/// <param name="Height">要求图片的高</param>
public static bool RemoteUpload(byte[] fileData, string ImgName, string ImgPath, double Width, double Height)
{
try
{
string _CustomEncryption = CustomEncryption();
if (fileData.Length == ) return false;
if (string.IsNullOrEmpty(ImgPath)) { ImgPath = "/Upload/User/" + PublicFun.MemberID(); }
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri(System.Configuration.ConfigurationManager.AppSettings["Resource_Url"] + "/Programs/MyGallery/UploadImg.ashx?CustomEncryption=" + _CustomEncryption + "&ImgName=" + ImgName + "&ImgPath=" + ImgPath + "&Width=" + Width + "&Height=" + Height)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
string htmlcode = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
if (htmlcode == "上传成功!")
{
return true;
}
else
{
return false;
} }
catch (Exception ex)
{
throw new Exception("文件上传失败", ex.InnerException);
}
}
/// <summary>
/// 远程删除图片
/// </summary>
/// <param name="fileName">文件路径</param>
/// <param name="Message">输出信息</param>
public static bool RemoteDelete_Img(string fileName, out string Message)
{
if (PublicFun.MemberID() > )
{
try
{
if (fileName.IndexOf("://") > )
{
fileName = PublicFun.RemovalUrl(fileName);
}
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/Delete_Img.ashx?fileName=" + fileName)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
Message = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
if (Message == "删除成功!")
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw new Exception("文件删除失败!", ex.InnerException);
}
}
else
{
Message = "请登录!";
return false;
}
}
/// <summary>
/// 远程删除图片/文件夹
/// </summary>
/// <param name="fileName">文件名</param>
public static bool RemoteDelete_File(string fileName)
{
int MemberID = PublicFun.MemberID();
string Message = "";
if (MemberID > )
{
try
{
if (fileName.IndexOf("/Upload/User/") < )
{
fileName = "/Upload/User/" + MemberID + "/" + fileName;
}
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/Delete_Img.ashx?fileName=" + fileName)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
Message = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close(); }
catch (Exception ex)
{
throw new Exception("文件删除失败!", ex.InnerException);
}
}
if (Message == "删除成功!")
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取我的图库
/// </summary>
/// <param name="Message">输出信息</param>
public static string GetMyGallery()
{
string Message = "";
try
{
if (PublicFun.MemberID() > )
{
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/GetMyGallery.ashx?MemberID=" + PublicFun.MemberID())) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
Message = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
return Message; }
catch (Exception ex)
{
throw new Exception("文件删除失败!", ex.InnerException);
}
}
/// <summary>
/// 创建文件夹
/// </summary>
/// <param name="FolderName">文件夹名称</param>
/// <param name="Message">输出信息</param>
public static string CreateFolder(string FolderName)
{
string Message = "";
try
{
if (PublicFun.MemberID() > )
{
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/CreateFolder.ashx?path=" + GetUploadPath(FolderName))) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
Message = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
return Message; }
catch (Exception ex)
{
throw new Exception("文件夹创建失败!", ex.InnerException);
}
}
/// <summary>
/// 文件重命名(包含文件夹)
/// </summary>
/// <param name="OldNmaePath">旧文件路径</param>
/// <param name="NewName">新文件名称</param>
/// <returns>文件重命名成功!(表示成功,其他消息表示失败)</returns>
public static string File_ReName(string OldNmaePath, string NewName)
{
string Message = "";
try
{
if (PublicFun.MemberID() > )
{
if (OldNmaePath.IndexOf("/Upload/User/") < )
{
OldNmaePath = "/Upload/User/" + PublicFun.MemberID() + "/" + OldNmaePath;
}
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/FileReName.ashx?OldNmaePath=" + GetUploadPath(OldNmaePath) + "&NewName=" + NewName)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
Message = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
return Message; }
catch (Exception ex)
{
throw new Exception("文件重命名失败!", ex.InnerException);
}
}
/// <summary>
/// 获取图库文件夹以及文件夹内的文件数
/// </summary>
/// <returns>(文件夹1,文件数/文件夹2,文件数.....)</returns>
public static string MyGalleryFolder()
{
string folder = "";
try
{
if (PublicFun.MemberID() > )
{
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/MyGalleryFolder.ashx?MemberID=" + PublicFun.MemberID())) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
folder = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
return folder; }
catch (Exception ex)
{
throw new Exception("获取失败!", ex.InnerException);
}
}
/// <summary>
/// 获取图库文件夹的文件
/// </summary>
/// <param name="Folder">文件夹名称</param>
/// <returns>文件,文件,......</returns>
public static string GetFolderFiles(string Folder)
{
string folder = "";
try
{
int MemberID = PublicFun.MemberID();
if (MemberID > )
{
string FolderPath = MemberID + "/" + Folder;
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/FolderFiles.ashx?FolderPath=" + FolderPath)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
folder = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
return folder; }
catch (Exception ex)
{
throw new Exception("获取失败!", ex.InnerException);
}
}
/// <summary>
/// 获取完整上传路径
/// </summary>
/// <param name="Path">原始路径</param>
/// <returns>返回完整路径</returns>
public static string GetUploadPath(string Path)
{
string NewPath = "Upload/User/" + PublicFun.MemberID() + "/";
if (!string.IsNullOrEmpty(Path))
{
if (Path.IndexOf(NewPath) > )
{
NewPath = Path;
}
else
{
NewPath += Path;
}
}
return NewPath; }
/// <summary>
/// 设置封面图片
/// </summary>
/// <param name="SourcePic">图片来源</param>
/// <param name="Folder">设置的文件夹</param>
/// <returns>bool</returns>
public static bool SetupCover(string SourcePic, string Folder)
{
string folder = "";
try
{
int MemberID = PublicFun.MemberID();
if (MemberID > )
{
string FolderPath = MemberID + "/" + Folder;
byte[] fileData = new byte[];
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/MyGallery/SetupCover.ashx?FilePath=" + SourcePic + "&Folder=" + FolderPath)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "POST";
request.ContentLength = fileData.Length;// 设置请求参数的长度. Stream stream = request.GetRequestStream();// 取得发向服务器的流
stream.WriteTimeout = ;
stream.Write(fileData, , fileData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
folder = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
if (folder.Trim() == "设置成功!")
{
return true;
}
else
return false; }
catch (Exception ex)
{
throw new Exception("获取失败!", ex.InnerException);
}
}
/// <summary>
/// 删除文件重命名文件
/// 王泳涛
/// </summary>
/// <param name="newpath">新的图片地址</param>
/// <param name="path">老的图片地址</param>
/// <returns></returns>
public static bool Delete(string newpath, string path)
{
string Message = "";
try
{
if (PublicFun.MemberID() > )
{
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(new Uri("http://localhost:94/Programs/Delete.ashx?path=" + path + "&newpath=" + newpath)) as System.Net.HttpWebRequest;
request.Headers["Cache-Control"] = "no-cache";
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();// GetResponse 方法才真的发送请求,等待服务器返回
Stream htmlstream = response.GetResponseStream();
StreamReader sr = new StreamReader(htmlstream);
Message = sr.ReadToEnd();//获得服务器返回内容
// 完成后要关闭字符流,字符流底层的字节流将会自动关闭
sr.Close();
htmlstream.Close();
response.Close();
}
}
catch (Exception e)
{
return false;
}
return true;
} <%@ WebHandler Language="C#" Class="UploadImg" %> using System;
using System.Web;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Text;
using System.Reflection; public class UploadImg : VerifyCode, IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
string fPath = context.Request.QueryString["ImgPath"];
string fName = context.Request.QueryString["ImgName"];
string Width = context.Request.QueryString["Width"];
string Height = context.Request.QueryString["Height"];
if (fName.IndexOf(".") < )
{
fName += ".jpg";
}
if (!string.IsNullOrEmpty(fPath) && !string.IsNullOrEmpty(fName))
{
var strem = HttpContext.Current.Request.InputStream;
long len = strem.Length;
if (len == )
{
strem.Close();
context.Response.ContentType = "text/plain";
context.Response.Write("传输错误!");
return; }
else
{
byte[] bytes = new byte[len];
string path = System.Web.HttpContext.Current.Server.MapPath("~/" + HttpUtility.UrlDecode(fPath));
int count = strem.Read(bytes, , bytes.Length);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
FileStream fStream = new FileStream(path + "/" + fName, FileMode.Create);
fStream.Write(bytes, , count);
fStream.Flush();
fStream.Close();
if (!string.IsNullOrEmpty(Width) && !string.IsNullOrEmpty(Height))
{
try
{
double targetWidth = Convert.ToDouble(Width);
double targetHeight = Convert.ToDouble(Height);
//原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
System.Drawing.Image initImage = System.Drawing.Image.FromStream(strem, true);
//原图宽高均小于模版,不作处理,直接保存 //缩略图宽、高计算
double newWidth = initImage.Width;
double newHeight = initImage.Height;
//宽大于高或宽等于高(横图或正方)
if (initImage.Width < initImage.Height || initImage.Width == initImage.Height)
{
//如果宽大于模版
if (initImage.Width > targetWidth)
{
//宽按模版,高按比例缩放
newWidth = targetWidth;
newHeight = initImage.Height * (targetWidth / initImage.Width);
}
}
//高大于宽(竖图)
else
{
//如果高大于模版
if (initImage.Height > targetHeight)
{
//高按模版,宽按比例缩放
newHeight = targetHeight;
newWidth = initImage.Width * (targetHeight / initImage.Height);
}
}
//生成新图
//新建一个bmp图片
System.Drawing.Image newImage = new System.Drawing.Bitmap((int)newWidth, (int)newHeight);
//新建一个画板
System.Drawing.Graphics newG = System.Drawing.Graphics.FromImage(newImage);
//设置质量
newG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
newG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//置背景色
newG.Clear(Color.White);
//画图
newG.DrawImage(initImage, new System.Drawing.Rectangle(, , newImage.Width, newImage.Height), new System.Drawing.Rectangle(, , initImage.Width, initImage.Height), System.Drawing.GraphicsUnit.Pixel); //保存缩略图
//newImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
newImage.Save(path + "\\s_" + fName);
//释放资源
newG.Dispose();
newImage.Dispose();
initImage.Dispose();
}
catch (Exception ex)
{
throw (ex);
}
}
strem.Close();
context.Response.ContentType = "text/plain";
context.Response.Write("上传成功!");
}
}
else
{
context.Response.ContentType = "text/plain";
context.Response.Write("传输错误!");
} } public bool IsReusable
{
get
{
return false;
}
} }
<%@ WebHandler Language="C#" Class="UploadAdImg" %> using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Net;
using Maticsoft.Common;
using System.Web.SessionState; public class UploadAdImg : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.Charset = "utf-8";
//string sessionid = context.Request.QueryString["sessionid"];
if (PublicFun.MemberID() < )
{
context.Response.Write("");
return;
}
HttpPostedFile file = context.Request.Files["FileData"];
//string UploadUrl = context.Request.QueryString["uploadurl"] ?? "http://localhost:94/Programs/UploadImg.ashx";//上传Url
string ImgPath = context.Request.QueryString["uploadpath"];//上传的路劲(从根开始文件夹路径)
//自定义命名
string ImgName =context.Request.QueryString["filename"]??string.Format("{0}", DateTime.Now.ToString("yyyyMMddhhmmssfff"));
ImgName +=PublicFun.GetImageType(file.FileName);
int id = -;
int.TryParse(context.Request.QueryString["id"], out id);
if (file != null)
{
byte[] bytes = new byte[file.InputStream.Length];
file.InputStream.Read(bytes,,bytes.Length);
file.InputStream.Close();
bool Istrue = false;
double width =;
double height =;
if (id == )
{
width = ;
height = ;
}
else if (id > )
{
width = ;
height = ;
}
if (width> && height>)
{
Istrue = Maticsoft.Common.PublicFun.RemoteUpload(bytes, ImgName, ImgPath, width, height);
}
else
{
Istrue = Maticsoft.Common.PublicFun.RemoteUpload(bytes, ImgName, ImgPath);
}
if (Istrue)//通过流上传资源站上传页面
{
string strurl = PublicVal.Resources_Url;//获取根目录 if (id>)
{
context.Response.Write( "/Upload/User/"+PublicFun.MemberID()+"/" + ImgName + "|" + (id-).ToString()); //返回图片的src
}
else
{
context.Response.Write(ImgPath + "/" + ImgName); //返回图片的src
}
}
else
{
context.Response.Write("");
}
}
else
{
context.Response.Write("");
}
context.Response.End();
} public bool IsReusable
{
get
{
return false;
}
} }
向服务器post或者get数据返回的更多相关文章
- java之初识服务器跨域获取数据
当一个项目膨大到无法进行整理时,而作为新负责维护的团队是非常苦恼的.对于想实现两个系统的数据访问,使用Ajax数据请求方式获取jsonp格式的数据 需要有前端jquery库文件. 前端代码通过jque ...
- php处理数据库数据,每处理一个数据返回客户端显示当前状态的方法。
php处理大量数据,每处理一个数据返回客户端显示当前状态的方法. 类似于dedecms生成静态页 想法: 客户端发送请求 服务器端接受请求,开始统计所需处理的数据量 将所需处理数据按一定规则排列,发送 ...
- ActionScript接收socket服务器发送来的数据
原文地址:http://www.asp119.com/news/2009522181815_1.htm 从socket中接收数据的方法取决于你使用socket类型,Socket和XMLSocket都可 ...
- jquery ajax请求成功,数据返回成功,seccess不执行的问题
1.状态码返回200--表明服务器正常响应了客户端的请求: 2.通过firebug和IE的httpWatcher可以看出服务器端返回了正常的数据,并且是符合业务逻辑的数据. ...
- C# 开发ModBus的服务器程序 实现ModBus数据总站 搭建自定义的Modbus服务器 同时支持tcp和rtu
前言 本文将使用一个NuGet公开的组件技术来实现一个ModBus TCP的服务器端数据引擎,方便的实现接收来自各种设备的数据.并且该服务器模拟真实的设备,包含了数据池功能,可以接受来自任何支持Mod ...
- js进阶ajax基本用法(创建对象,连接服务器,发送请求,获取服务器传过来的数据)
js进阶ajax基本用法(创建对象,连接服务器,发送请求,获取服务器传过来的数据) 一.总结 1.ajax的浏览器的window对象的XMLHtmlRequest对象的两个重要方法:open(),se ...
- Nginx下HTML页面POST请求静态JSON数据返回405状态
在浏览器访问HTML页面,发现一些静态JSON数据没有显示,F12查看,如下图所示: 可以看到请求方式为POST 将请求链接复制在浏览器地址栏访问,可以正常请求到数据 F12查看,可以看到请求方式为G ...
- ESA2GJK1DH1K升级篇: 远程升级准备工作: 使用TCP客户端连接Web服务器实现http下载数据
一,根目录建一个文件 二,使用浏览器访问 http://47.92.31.46:80/1.txt 或者 http://47.92.31.46/1.txt 三,使用TCP客户端访问文件内容 3 ...
- 序列化和反序列化在浏览器和 Web 服务器之间传递的数据、加密解密
js中数组不能传递到后台,需进行json序列化: var data = new Array(); data.push({para1:name,para2:answer}); string data = ...
随机推荐
- flask小demo-数据查询
mysqlconn-flask.py # -*- coding: utf-8 -*- #coding=utf-8 import os import mysql.connector from flask ...
- Redis笔记(三):Redis常用命令
连接测试 连接本地服务器 语法 $ redis-cli 实例 启动 redis 客户端,打开终端并输入命令 redis-cli.该命令会连接本地的 redis 服务. $redis-cli redis ...
- mongodb-mongotemplate进行地理坐标操作
因为项目中使用的springboot + mongotemplate, 所以还是需要mongotemplate的操作方式 首先建立一个bean: package com.iwhere.easy.tra ...
- 堆排序详解以及java实现
前言 临近毕业,开始找工作,近期一直在看算法导论(CLRS)同时各种刷题.希望以后有时间把所有学习心得和刷题心得记录下来. 堆 堆排序和合并排序一样,是一种时间复杂度为O(nlgn)的算法,同时和插入 ...
- Golang 并发Groutine实例解读(二)
go提供了sync包和channel机制来解决协程间的同步与通信. 一.sync.WaitGroup sync包中的WaitGroup实现了一个类似任务队列的结构,你可以向队列中加入任务,任务完成后就 ...
- ClickOnce 发布WinForm应用程序(非签名方式)
ClickOnce IIS7发布WinForm应用程序,非签名方式(不勾选签名中的"为ClickOnce清单签名") 一.在D盘上建一个文件夹”MyAppPath”. 该 ...
- MyEclipse设置当前行背景颜色、选中单词前景色、背景色
General->Editors->Text Editors -> Current Line Hightlight 可以设置当前行的背景颜色 效果如下:
- oracle网页客户端工具
Oracle数据库的管理相较于其他数据库,是比较麻烦的,客户端工具的安装都要花一些时间,目前有一款treesoft软件,通过网页的方式管理Oracle. 功能包括:数据库的展示,库表的展示,表字段结构 ...
- AutoFac在项目中应用的体会
AutoFac的工作原理就是:注册类并映射到接口,通过注入后返回相应实例化的类! 先来简单介绍下Autofac的使用 1.通过Nuget或代码安装autofac 安装autofac :ins ...
- HTML5:'data-'属性的作用是什么
在大家查看HTML时,经常会看到data-role.data-theme等的使用,比如:通过如下代码即可实现页眉的效果: <div data-role="header"> ...