向服务器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 = ...
随机推荐
- VMware Workstation 11 中 Ubuntu 14.04 的 VMware Tools 问题 :没有显示共享文件夹
症状:主要表现在Win7中用VM11安装的Ubuntu14.04中,安装完自带的VMware Tools之后,/mnt/hgfs 中没有前面已经设置好的共享文件夹. 仔细查看了安装过程,发现在 ...
- TemplateBinding和Binding的区别
定义 TemplateBinding是为了某个特定场景优化出来的数据绑定版本--需要把ControlTemplate里面的某个Property绑定到应用该ControlTemplate的控件的对应Pr ...
- Node.js http服务器搭建和发送http的get、post请求
1.Node.js 搭建http服务器 1.1创建server.js var http = require('http'); var querystring = require('querystrin ...
- SQL Server附加数据库拒绝访问解决方法汇总
@本文来自百度 方法一:修改权限法 1 打开要附加的数据库文件所在的文件夹,即扩展名为mdf的文件所在的文件夹,如下图所示: 2 右键单击mdf文件,选择“属性”,如下图所示: 3 单击“安全”选项卡 ...
- python学习之参数传递
^参数传递分为定义(形参)和调用(实参)两种情况.^ 1. 定义(形参) 默认参数 def func(x, y=None): # 任何时候必须 优先定义 位置参数 # 默认参数和可变参数*args 顺 ...
- 从Object对象中读取属性的值
C#是强类型语言,强到多变态?一个对象没有定义某个属性,你想点出来,IDE直接给你报语法错误.远不如js那么自由,想怎么点怎么点. 如果你从别人接口中拿到的就是Object类型,你想获取某个属性的值怎 ...
- [日常] Go语言圣经-GIF动画练习语法
1.常量声明的值必须是一个数字值.字符串或者一个固定的boolean值.2.常量声明和变量声明一般都会出现在包级别3.[]color.Color{...}生成的是一个slice切片和gif.GIF{. ...
- 四:Jquery-animate
动画效果: 1.显示/隐藏动画效果 动态的改变当前元素的宽,高和不透明度 show([duration],[fn]); //显示当前元素 hide([duration],[fn]); //隐藏当前元素 ...
- VIM命令图解
右键在新窗口打开查看大图 删除所有:dG 来源见水印
- 撩课-Web大前端每天5道面试题-Day22
1.mvvm和mvc区别?它和其它框架(jquery)的区别是什么?哪些场景适合? mvc和mvvm其实区别并不大. 都是一种设计思想. 主要就是mvc中Controller演变成mvvm中的view ...