惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
量子位
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
博客园 - Franky
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog

博客园 - RainWaterLily

[转贴]如何在3个月内拥有3年的工作经验 [转帖]四种不正确的职业心态 (转载)HP大中华区总裁孙振耀畅谈工作与生活 什么是脑图?(转贴) 创建SQL Server数据库时,首先判断数据库文件是否存在 获取当前正在使用的SQL 数据库 SQL语句获取数据库文件全路径 MS SQL Server 2005 无法远程连接 windows计划任务 见“利”忘“义”??? [转]post和get的不同之处 [转]C# 向web网站GET、POST 数据 SQL2005常见性能问题排错演示代码[收藏] sp_fulltext_service (Transact-SQL) 设计模式的原则(转) Extending SQL 2005 Fulltext Search (转载) 感悟(转载) [美]杰克·韦尔奇《赢》摘记 转载:动态调用WebService(C#)
[转]C# GET、POST方式请求web
RainWaterLily · 2008-05-26 · via 博客园 - RainWaterLily

2008-04-10 12:50

private string GetModel(string strUrl)
   {
    string strRet = null;
    try
    {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
     request.Timeout = 2000;
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
   
     System.IO.Stream resStream = response.GetResponseStream();  
     Encoding encode = System.Text.Encoding.Default;
     StreamReader readStream = new StreamReader( resStream, encode );

     Char[] read = new Char[256];
     int count = readStream.Read( read, 0, 256 );
     while (count > 0)
     {
      String str = new String(read, 0, count);
      strRet = strRet + str;
      count = readStream.Read(read, 0, 256);
     }

     resStream.Close();
    }
    catch(Exception e)
    {
     strRet="";
    }
    return strRet;
   }

public static string PostModel(string strUrl, string strParm)
   {
    Encoding encode = System.Text.Encoding.Default;

    byte[] arrB = encode.GetBytes(strParm);
    string strBaseUrl = null;
  
    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strUrl);
    myReq.Method = "POST" ;
    myReq.ContentType = "application/x-www-form-urlencoded";
    myReq.ContentLength = arrB.Length;
    Stream outStream = myReq.GetRequestStream();           
    outStream.Write(arrB,0,arrB.Length);
    outStream.Close();
               WebResponse myResp = null;
    try
    {
     //接收HTTP做出的响应
     myResp = myReq.GetResponse();
    }
    catch(Exception e)
    {
      int ii =0;
    }
    Stream ReceiveStream = myResp.GetResponseStream();               
    StreamReader readStream = new StreamReader( ReceiveStream, encode );
    Char[] read = new Char[256];
    int count = readStream.Read( read, 0, 256 );
    string str = null;
    while (count > 0)
    {
     str += new String(read, 0, count);
     count = readStream.Read(read, 0, 256);
    }
    readStream.Close();
    myResp.Close();
               return str;
   }

posted on 2008-05-26 11:54  RainWaterLily  阅读(1518)  评论()    收藏  举报