乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      詳細(xì)GET和POST方法

       靜女奇姝 2016-05-13
      Get是用來從服務(wù)器上獲得數(shù)據(jù),而Post是用來向服務(wù)器上傳遞數(shù)據(jù).

      HTTP同步請求

              // get請求是查詢字符串直接跟在URL后面
              
      //post是把消息體包含查詢字符串,滿足把大量數(shù)據(jù)傳遞給服務(wù)器

              
      //發(fā)送請求,"url"為訪問的地址
              HttpWebRequest req = (HttpWebRequest)WebRequest.Create("url");
              //ContentType為數(shù)據(jù)類型
              
      //get請求ContentType為空,post請求ContentType為application/x-www-form-urlencoded
              req.ContentType = "";
              req.Method = "get";  //請求方法為get和post
              
      //content消息體,get請求content為空,post請求為要傳遞的參數(shù),如“AcctID=1
              string content = "";
              req.ContentLength=content.Length;
              Stream s;

              s = req.GetRequestStream();//獲取請求數(shù)據(jù)

              StreamWriter sw = new StreamWriter(s, System.Text.Encoding.ASCII);

              sw.Write(content);

              sw.Close();

              //得到HTTP請求

             HttpWebResponse  res = (HttpWebResponse)req.GetResponse();
             s = res.GetResponseStream();

             StreamReader sr = new StreamReader(s, System.Text.Encoding.ASCII);
             System.Text.StringBuilder sb = new System.Text.StringBuilder();

             char[] data = new char[1024];

             int nBytes;

             do
             {
                 nBytes = sr.Read(data, 0, (int)1024);
                 sb.Append(data);
             } while (nBytes == 1024);
      HTTP異步請求
              //發(fā)送請求,"url"為訪問的地址
              HttpWebRequest req = (HttpWebRequest)WebRequest.Create("url");
              //ContentType為數(shù)據(jù)類型
              
      //get請求ContentType為空,post請求ContentType為application/x-www-form-urlencoded
              req.ContentType = "";
              req.Method = "get";  //請求方法為get和post
              
      //content消息體,get請求content為空,post請求為要傳遞的參數(shù),如“AcctID=1
              string content = "";
              req.ContentLength=content.Length;
              Stream s;

              s = req.GetRequestStream();//獲取請求數(shù)據(jù)

              StreamWriter sw = new StreamWriter(s, System.Text.Encoding.ASCII);

              sw.Write(content);

              sw.Close();
              Handler h = new Handler();
              AsyncCallback callback = new AsyncCallback(h.Callback); //方法
              
      //將請求對象作為狀態(tài)對象傳遞
              req.BeginGetResponse(callback, req);
      回調(diào)函數(shù),用類來表示
          public class Handler
          {
              public void Callback(IAsyncResult ar)
              {
                  //將Requeststate對象強(qiáng)制轉(zhuǎn)化為webRequest對象
                  HttpWebRequest req = (HttpWebRequest)ar.AsyncState;

                  //得到與這個(gè)請求相關(guān)的響應(yīng)對象
                  HttpWebResponse res = (HttpWebResponse)req.EndGetResponse(ar);

                  //開始從響應(yīng)流中讀取數(shù)據(jù)
                  Stream s = res.GetResponseStream();

                  StreamReader sr = new StreamReader(s, System.Text.Encoding.ASCII);
                  System.Text.StringBuilder sb = new System.Text.StringBuilder();

                  char[] data = new char[1024];

                  int nBytes;

                  do
                  {
                      nBytes = sr.Read(data, 0, (int)1024);
                      sb.Append(data);
                  } while (nBytes == 1024);

              }
          }

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

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多