日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

c# cs與bs數(shù)據(jù)請求交換

 昵稱10504424 2013-02-19
C# cs發(fā)送http get請求
C#代碼 復(fù)制代碼 收藏代碼
  1. try  
  2. {   
  3.     WebRequest req = WebRequest.Create("http://127.0.0.1/test/loginsso.aspx?username=admin&password=admin");   
  4.     req.Method = "POST";   //指定提交的Method,可以為POST和GET,一定要大寫    
  5.   
  6.     //byte[] postData = System.Text.Encoding.GetEncoding("gbk").GetBytes("?username=admin&password=admin");//Post的數(shù)據(jù)    
  7.   
  8.     //req.ContentLength = postData.Length;   
  9.     Stream postStream = req.GetRequestStream();   
  10.     //postStream.Write(postData, 0, postData.Length);   
  11.     postStream.Close();   
  12.   
  13.     WebResponse res = req.GetResponse();   
  14.   
  15.     System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("utf-8");//接收的編碼    
  16.     StreamReader reader = new StreamReader(res.GetResponseStream(), resEncoding);   
  17.   
  18.     string html = reader.ReadToEnd();     //接收的Html    
  19.     MessageBox.Show("=========" + html);   
  20.   
  21.     reader.Close();   
  22.     res.Close();   
  23. }   
  24. catch (Exception ex)   
  25. {   
  26.     MessageBox.Show("error");   
  27. }  

.net 接收get發(fā)送請求
C#代碼 復(fù)制代碼 收藏代碼
  1. Response.ContentEncoding = Encoding.GetEncoding("UTF-8");   
  2.            string username = Request["username"];   
  3.            string password = Request["password"];   
  4.   
  5.            if (username != "" && username == "admin" && password != "" && password == "admin")   
  6.            {   
  7.                Response.Write("success");   
  8.            }   
  9.            else  
  10.            {   
  11.                Response.Write("error" + Request.Url.Host);   
  12.               // Response.Redirect("http://www.");   
  13.          }  

.net 接收post請求
C#代碼 復(fù)制代碼 收藏代碼
  1. System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("utf-8");//接收的編碼   
  2.                 StreamReader reader = new StreamReader(Request.InputStream, resEncoding);   
  3.                 string msg = reader.ReadToEnd();   
  4.                 reader.Close();  


c# cs發(fā)送圖片附件
C#代碼 復(fù)制代碼 收藏代碼
  1. if (!textBox_fileName.Text.Trim().Equals(""))   
  2.             {   
  3.                 string loadFile = textBox_fileName.Text.Trim();   
  4.                 string fileName = loadFile.Substring(loadFile.LastIndexOf("\\") + 1, loadFile.Length - 1 - loadFile.LastIndexOf("\\"));   
  5.                 string urlStr = @"http://127.0.0.1/test/UploadFile.aspx?name=" + fileName;   
  6.                 UploadFileBinary(loadFile, urlStr);   
  7.             }   
  8.             else  
  9.             {   
  10.                 string alStr = "您還沒有選擇文件";   
  11.                 MessageBox.Show(alStr, "系統(tǒng)提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);   
  12.             }  

C#代碼 復(fù)制代碼 收藏代碼
  1. public  void UploadFileBinary(string localFile, string uploadUrl)   
  2.         {   
  3.             try  
  4.             {   
  5.   
  6.                 FileStream rdr = new FileStream(localFile, FileMode.Open);   
  7.                 byte[] inData = new byte[4096];   
  8.                 int totbytes = 0;   
  9.                 MemoryStream postData = new MemoryStream();   
  10.                 int bytesRead = rdr.Read(inData, 0, inData.Length);   
  11.                 while (bytesRead > 0)   
  12.                 {   
  13.                     postData.Write(inData, 0, bytesRead);   
  14.                     bytesRead = rdr.Read(inData, 0, inData.Length);   
  15.                     totbytes += bytesRead;   
  16.                 }   
  17.                 rdr.Close();   
  18.                 postData.Position = 0;   
  19.                 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);   
  20.                 req.Method = "POST";   
  21.                 req.ContentLength = (long)postData.Length;   
  22.                 using (Stream s = req.GetRequestStream())   
  23.                 {   
  24.                     s.Write(postData.ToArray(), 0, (int)postData.Length);   
  25.                     postData.Close();   
  26.                 }   
  27.                 WebResponse resp = req.GetResponse();   
  28.                 System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("utf-8");//接收的編碼   
  29.                 StreamReader reader = new StreamReader(resp.GetResponseStream(), resEncoding);   
  30.                 string msg = reader.ReadToEnd();   
  31.                 reader.Close();   
  32.                 resp.Close();   
  33.                 if (msg != null && msg.Equals("success"))   
  34.                 {   
  35.                     MessageBox.Show("圖片上傳成功","提示");   
  36.                 }   
  37.             }   
  38.             catch (Exception ex)   
  39.             {   
  40.                 //string exContent;   
  41.                 // exContent = ex.ToString();   
  42.                 MessageBox.Show("上傳失??!網(wǎng)絡(luò)出現(xiàn)異?;蛘邎D片文件已經(jīng)存在!","提示");   
  43.   
  44.             }   
  45.   
  46.         }  

.net 接收圖片附件文件
C#代碼 復(fù)制代碼 收藏代碼
  1. Response.ContentEncoding = Encoding.GetEncoding("UTF-8");   
  2.   
  3.              // 在此處放置用戶代碼以初始化頁面   
  4.             byte[] theData = null;   
  5.             String ls_name;   
  6.             if (Request.ServerVariables["REQUEST_METHOD"].ToString().ToUpper() == "POST")   
  7.             {   
  8.              theData = Request.BinaryRead(Request.ContentLength);    
  9.              //獲取文件名稱   
  10.              ls_name = Request.QueryString["name"];            
  11.              //string picName = DateTime.Now.Ticks.ToString() + ".gif";     
  12.              //string picName = DateTime.Now.Ticks.ToString() + ".jpg";   
  13.              FileStream stm = new FileStream(Server.MapPath("uploadfile/"+ls_name), System.IO.FileMode.CreateNew);   
  14.              stm.Write(theData, 0, (int)theData.Length);   
  15.              stm.Close();   
  16.              Response.Write("success");   
  17.              }   
  18.              else  
  19.              {   
  20.                Response.Write("error");   
  21.              }   

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多