winform中: string test = "julim";
HttpWebRequest request = HttpWebRequest.Create("http://localhost/test/Default.aspx?test=" + test + "") as HttpWebRequest;
request.Method = "POST";webform中:try
{
uid = string.Empty;
if (Request.QueryString["test"].ToString() != "")
{
uid = Request.QueryString["test"].ToString();
Response.Write(uid);
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}前两天做的一个程序也是这样传值、接收值,今天一试就不行了!
错误提示:未将对象引用设置到对象实例。传过去的"test"始终为空值。我只是让客户端传过去值,先把服务器端的回应问题放一边。
HttpWebRequest request = HttpWebRequest.Create("http://localhost/test/Default.aspx?test=" + test + "") as HttpWebRequest;
request.Method = "POST";webform中:try
{
uid = string.Empty;
if (Request.QueryString["test"].ToString() != "")
{
uid = Request.QueryString["test"].ToString();
Response.Write(uid);
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}前两天做的一个程序也是这样传值、接收值,今天一试就不行了!
错误提示:未将对象引用设置到对象实例。传过去的"test"始终为空值。我只是让客户端传过去值,先把服务器端的回应问题放一边。
解决方案 »
- 已经安装了Gtk#,为什么安装monodevelop时提示Gtk# version 2.12.9 or greater must be installed……
- 新手。。。。。。。。。。
- 如何用c#开发下载考勤机数据的程序
- 关于线程分配到CPU的8个核上(如果有朋友能回答分再加)
- 100分求动态生成的表,动态生成表单的解决办法。
- 求一正则
- datagrid模板列排序问题
- 在ASP.NET Web应用中如何调用WindowsAPI???
- 请问ftp续传是怎么实现的?
- TCP/IP通讯
- [winform] DataGridView的右键菜单
- VS2008中的DataGridView各列的数据格式问题?
if (Request.QueryString["test"].ToString() != "")
最好写成
if (Request.QueryString["test"] != null )
你看看
///string postData = Get_mb_reg_auth(mybossInfo);
System.Net.HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(myurl); //http://192.168.6.199:8080 http://oa.walkwatch.com
Request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytePost = encoding.GetBytes(postData);
Request.ContentType = "application/x-www-form-urlencoded";
Request.ContentLength = postData.Length;
Stream newStream = Request.GetRequestStream();
newStream.Write(bytePost, 0, bytePost.Length);
System.Net.WebResponse Response = Request.GetResponse();
System.IO.Stream stream = Response.GetResponseStream();
System.IO.StreamReader reader = new StreamReader(stream);
myxml = reader.ReadToEnd();
这个段码是以前我帮同事写的口碑网的提交代码。
static void send(int index)
{
string[] city=citys[index].Split(':');
string uriString = string.Format("http://{0}.koubei.com/fenlei/postlocal.html?city={1}&categoryId=92&district=0",city[0],city[1]);
WebClient myWebClient = new WebClient();
string postData = null;
byte[] byteArray;
byte[] responseArray;
WebHeaderCollection myWebHeaderCollection;
postData = GetHtml("info.txt").Replace("{0}",city[1]);
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
myWebClient.Headers.Add("Referer",string.Format("http://{0}.koubei.com/fenlei/fenleiform.html?city={1}&categoryId=92&district=0",city[0],city[1]));
myWebClient.Headers.Add("Accept-Language","zh-cn");
myWebClient.Headers.Add("Cookie",string.Format("MyKoubeiCity={0}; bblastvisit=1181210845; LogonName=hbwxzzq; last_visit_fenlei=690194:690178:690100:690114:690141:690134:; JSESSIONID=FC7081353F43E70CB73F99150D959D1E.app21; hold=1; TRAddCookie=header%3B19252625%2Cmapall%2Ccheck_fang_first%2Chuangye_bensou%2Ccheck_fang_first%2Ccheck_fang_first; Source=19252625%3Bmapall; __utma=90229888.374677196.1181287051.1181287051.1181287051.1; __utmb=90229888; __utmc=90229888; __utmz=90229888.1181288893.1.3.utmccn=(organic)|utmcsr=baidu|utmctr=%CE%DE%CE%FD%BF%DA%B1%AE%CD%F8|utmcmd=organic; PHPSESSID=fef8a322a722f8b7a4f882caee250d37; Koubei_User=hbwxzzq; MyEleaseCookie=MjI3NDQxMjQ2#913bh+1EtA==; MyEleaseCookiep=NjA0NTQxMTQx#zc3Uk7S4pR0O8HmRek6iZxTvqOVAEslzBrj2bGN/NVY=; bbuserid=3117046; bbpassword=7c83400f996a3c801648e7b2431a449f",city[1]));//通过抓包工具得到的cookie
myWebHeaderCollection = myWebClient.Headers;
//第一次交互
Console.WriteLine("发送的HTTP头信息");
for (int i=0; i < myWebHeaderCollection.Count; i++)
{
Console.WriteLine (myWebHeaderCollection.GetKey(i) + " : " + myWebHeaderCollection.Get(i));
}
byteArray = Encoding.Default.GetBytes(postData);
responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
Console.WriteLine("接收的HTTP头信息");
myWebHeaderCollection = myWebClient.ResponseHeaders;
for (int i=0; i < myWebHeaderCollection.Count; i++)
{
Console.WriteLine (myWebHeaderCollection.GetKey(i) + " : " + myWebHeaderCollection.Get(i));
}
Console.WriteLine("接收的正文信息");
Console.WriteLine(Encoding.Default.GetString(responseArray));
}
string test = "julim";
string uriString = string.Format("http://localhost/test/Default.aspx?test={0}",test);
WebClient myWebClient = new WebClient();
string postData = null;
byte[] byteArray;
byte[] responseArray;
WebHeaderCollection myWebHeaderCollection;
postData = "";//这个地方填你通过post提交的表单数据
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
myWebClient.Headers.Add("Accept-Language","zh-cn");
myWebClient.Headers.Add("Cookie","");//通过抓包工具得到的cookie
myWebHeaderCollection = myWebClient.Headers;
byteArray = Encoding.Default.GetBytes(postData);
myWebClient.UploadData(uriString,"POST",byteArray); 这个是C#的码。
LS的方法我试了,不管是Form接收还是QueryString接收都得不到值。