zoukankan      html  css  js  c++  java
  • C#(asp.net )读取ASHX文件(一般处理程序)

    c#后台获取asxh的返回数据,后台创建一个请求实例,获取请求实例的返回值

        public string GetResponseByPost(string apiUrl, string queryString)
        {
            string responseString = string.Empty;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(apiUrl + queryString);
            request.ContentType = "text/html";
            request.Method = "POST";
            request.ContentLength = queryString.Length;
            request.Timeout = 20000;
            byte[] bytes = Encoding.UTF8.GetBytes(queryString);
            Stream os = null;
            try
            { // send the Post
                request.ContentLength = bytes.Length;   //Count bytes to send
                os = request.GetRequestStream();
                os.Write(bytes, 0, bytes.Length);         //Send it
            }
            catch (WebException ex)
            {
                throw ex;
            }
            finally
            {
                if (os != null)
                {
                    os.Close();
                }
            }
    
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    responseString = reader.ReadToEnd();
                }
            }
            catch (Exception ex2)
            {
                throw ex2;
            }
            finally
            {
                if (response != null)
                    response.Close();
            }
            return responseString;
        }
    

      程序员的基础教程:菜鸟程序员

  • 相关阅读:
    java修改应用程序标题栏
    电动双轮车
    Oracle执行计划相关(待补充)
    SQL中IN和EXISTS用法的区别
    union all与union all
    equals与hashcode
    文件上传的整个流程
    adwords与adsence
    struts2文件上传大小
    为什么是UUID做主键
  • 原文地址:https://www.cnblogs.com/guohu/p/6148203.html
Copyright © 2011-2022 走看看