110,536
社区成员
发帖
与我相关
我的任务
分享
Encoding encoding = Encoding.GetEncoding("utf-8");
string postData = "{\"wymc\":\"6\"}";
string strUrl = "http://esf.bxgfw.com/ajaxpro/user_admin_renthouse_pub,App_Web__nxws2da.ashx?";
byte[] data = encoding.GetBytes(postData);
// 准备请求... {"mcstr":"è¾½ä¸"}
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.Referer = "http://esf.bxgfw.com/shop/admin/renthouse_pub.aspx";
myRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
myRequest.Headers.Add("X-AjaxPro-Method", "getSearchList");
myRequest.ContentType = "application/x-www-form-urlencoded";
//注意这里的Cookie进行更换成你的登录信息
myRequest.Headers.Add("Cookie", "ASP.NET_SessionId=42jidiukrk5d1cugei0bhsup; cnzz_a2178262=6; sin2178262=; rtime=0; ltime=1294802416124; cnzz_eid=41664513-1294801319-http%3A//esf.bxgfw.com/shop/admin/renthouse_pub.aspx; lzstat_uv=38694578793119418740|1524099; lzstat_ss=3351439025_2_1294830879_1524099; user=hyloginstate=success!&hybh=G11011211150315&hylx=%b8%f6%c8%cb%bb%e1%d4%b1&hyzh=net_lover&hyyj=&hyjb=%c6%d5%cd%a8%bb%e1%d4%b1&hyjf=0&hysftgyz=1&hymc=%c0%ed%cf%eb&hylxdh=13910309166&hylxr=net_lover");
myRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
//得到服务器端的返回
HttpWebResponse res = myRequest.GetResponse() as HttpWebResponse;
StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.GetEncoding("utf-8"));
Response.Write(sr.ReadToEnd());
sr.Close();
res.Close();
if(typeof user_admin_renthouse_pub == "undefined") user_admin_renthouse_pub={};
user_admin_renthouse_pub_class = function() {};
Object.extend(user_admin_renthouse_pub_class.prototype, Object.extend(new AjaxPro.AjaxClass(), {
Getqxsq: function(mcstr) {
return this.invoke("Getqxsq", {"mcstr":mcstr}, this.Getqxsq.getArguments().slice(1));
},
getSearchList: function(wymc) {
return this.invoke("getSearchList", {"wymc":wymc}, this.getSearchList.getArguments().slice(1));
},
getSearchListResult: function(wymc) {
return this.invoke("getSearchListResult", {"wymc":wymc}, this.getSearchListResult.getArguments().slice(1));
},
url: '/ajaxpro/user_admin_renthouse_pub,App_Web__nxws2da.ashx'
}));
user_admin_renthouse_pub = new user_admin_renthouse_pub_class();
string accept = "*/*";
string userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
Encoding encoding = Encoding.GetEncoding("utf-8");
CookieContainer cc = PublishVoid.htLogin[LoginUrl] as CookieContainer;
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null;
byte[] byteRequest = Encoding.Default.GetBytes("{'wymc':'" + System.Web.HttpUtility.UrlEncode("金", Encoding.GetEncoding("utf-8"))+"'}");
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(GetXiaoQuUrl);
httpWebRequest.CookieContainer = cc;
httpWebRequest.ContentType = "text/plain; charset=utf-8";
httpWebRequest.Referer = "http://esf.bxgfw.com/shop/admin/renthouse_pub.aspx";
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = byteRequest.Length;
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.Headers.Add("x-ajaxpro-method", "getSearchList");
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
httpWebResponse.Cookies = cc.GetCookies(httpWebRequest.RequestUri);
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, encoding);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
httpWebRequest.Abort();
httpWebResponse.Close();
byte[] byteRequest = Encoding.Default.GetBytes(postData);
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.ServicePoint.ConnectionLimit = maxTry;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = isPost ? "POST" : "GET";
httpWebRequest.ContentLength = byteRequest.Length;
httpWebRequest.AllowAutoRedirect = true;
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
httpWebResponse.Cookies = cookieContainer.GetCookies(httpWebRequest.RequestUri);
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, encoding);
//cc.SetCookies(httpWebRequest.RequestUri);
cc = cookieContainer;
if (!(PublishVoid.htLogin.Contains(url)))
PublishVoid.htLogin.Add(url, cc);
string html = streamReader.ReadToEnd();
Encoding encoding = Encoding.GetEncoding("utf-8");
string postData = "{'A':'测试'}";
string strUrl = "http://localhost:57606/WebSite1/HttpReceiveData.ashx";
byte[] data = encoding.GetBytes(postData);
// 准备请求...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
//得到服务器端的返回
HttpWebResponse res = myRequest.GetResponse() as HttpWebResponse;
StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.GetEncoding("utf-8"));
Response.Write(sr.ReadToEnd());//或者MessageBox.Show(sr.ReadToEnd());
sr.Close();
res.Close();
<%@ WebHandler Language="C#" Class="HttpReceiveData" %>
using System;
using System.Web;
public class HttpReceiveData : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream, System.Text.Encoding.GetEncoding("utf-8"));
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Write("接收到的值是:" + sr.ReadToEnd());
sr.Close();
}
public bool IsReusable
{
get
{
return false;
}
}
}
Encoding encoding = Encoding.GetEncoding("GB2312");
string postData = "{'A':'测试'}";
string strUrl = "http://xxxxxxxxxxxxxxxxxxxxxx/HttpReceiveData.ashx";
byte[] data = encoding.GetBytes(postData);
// 准备请求...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// 发送数据
newStream.Write(data,0,data.Length);
newStream.Close();