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"始终为空值。我只是让客户端传过去值,先把服务器端的回应问题放一边。

解决方案 »

  1.   

    应该都没有问题
     if (Request.QueryString["test"].ToString() != "") 
    最好写成
     if (Request.QueryString["test"] != null ) 
      

  2.   

    这是本人在公司在线的代码
    你看看
    ///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();  
      

  3.   

    我一般都用这样的方法向web服务器端发送的。
    这个段码是以前我帮同事写的口碑网的提交代码。
    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));  
       }
      

  4.   


    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#的码。
      

  5.   

    不能沉啊。。
    LS的方法我试了,不管是Form接收还是QueryString接收都得不到值。
      

  6.   

    不会吧,你的aspx程序那边是不是牵扯到别的东西了?好好检查一下,或者在Page_Load里直接输出Response.Write("test")看出错吗?你可以再建立一个工程进行测试,看看是否是其他相关的东西造成的问题。