zoukankan      html  css  js  c++  java
  • 跟据URL来实现WebService

     [WebMethod]
            
    public string GetResults(string word)
            {
                
    string resultHtml = string.Empty;

                
    //将输入的字符串转成URL编码
                string myWord = HttpUtility.UrlEncode(word, UnicodeEncoding.GetEncoding("GB2312"));

                
    //引用System.Net空间,创建一个新的请求;
                HttpWebRequest webrt = WebRequest.Create("http://www.baidu.com/s?wd=" + myWord) as HttpWebRequest;
                
    //获取响应;
                HttpWebResponse webrs = webrt.GetResponse() as HttpWebResponse;

                
    //读取响应内容;
                Stream stream = webrs.GetResponseStream();
                StreamReader reader 
    = new StreamReader(stream, Encoding.Default);
                
    //结束读取;
                resultHtml = reader.ReadToEnd();

                reader.Close();
                stream.Close();
                webrs.Close();

                
    //返回结果
                return resultHtml;
            }
  • 相关阅读:
    python 之 xlrd模块 excel的读使用
    将str文本类型转换为dict
    pycharm快捷键、常用设置、配置管理
    Bye bye bye
    课题一--作业复习
    python 整齐输出与编码读写
    图像分割——并行区域技术
    主动轮廓模型(重点)
    边界技术
    二阶导数算子
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2091015.html
Copyright © 2011-2022 走看看