模态MFC框架窗口

Posted dincat

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模态MFC框架窗口相关的知识,希望对你有一定的参考价值。

using System;
using System.IO;
using System.Net;
using System.Text;

public class MyWebRequest
{
    private WebRequest request;
    private Stream dataStream;

    private string status;

    public String Status
    {
        get
        {
            return status;
        }
        set
        {
            status = value;
        }
    }

    /// <summary>
    /// 直接请求的
    /// </summary>
    /// <param name="url"></param>
    public MyWebRequest(string url)
    {
        // Create a request using a URL that can receive a post.

        request = WebRequest.Create(url);
    }


    /// <summary>
    /// 不带参数的get/post
    /// </summary>
    /// <param name="url"></param>
    /// <param name="method"></param>
    public MyWebRequest(string url, string method)
        : this(url)
    {

        if (method.Equals("GET") || method.Equals("POST"))
        {
            // Set the Method property of the request to POST.
            request.Method = method;
        }
        else
        {
            throw new Exception("Invalid Method Type");
        }
    }

    /// <summary>
    /// 带参数的get/post
    /// </summary>
    /// <param name="url"></param>
    /// <param name="method"></param>
    /// <param name="data"></param>
    /// <param name="contentType">用下面的HttpContentType类中的常量</param>
    public MyWebRequest(string url, string method, string data, string contentType)
        : this(url, method)
    {

        // Create POST data and convert it to a byte array.
        string postData = data;
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        // Set the ContentType property of the WebRequest.
        //request.ContentType = "application/x-www-form-urlencoded";
        request.ContentType = contentType;

        // Set the ContentLength property of the WebRequest.
        request.ContentLength = byteArray.Length;

        // Get the request stream.
        dataStream = request.GetRequestStream();

        // Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length);

        // Close the Stream object.
        dataStream.Close();

    }

    public string GetResponse()
    {
        WebResponse response = request.GetResponse();
        this.Status = ((HttpWebResponse)response).StatusDescription;
        dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();

        //释放
        reader.Close();
        dataStream.Close();
        response.Close();

        return responseFromServer;//返回数据
    }


    /// <summary>
    /// HTTP 内容类型(Content-Type)
    /// </summary>
    public class HttpContentType
    {
        /// <summary>
        /// 资源类型:普通文本
        /// </summary>
        public const string TEXT_PLAIN = "text/plain";

        /// <summary>
        /// 资源类型:JSON字符串
        /// </summary>
        public const string APPLICATION_JSON = "application/json";

        /// <summary>
        /// 资源类型:未知类型(数据流)
        /// </summary>
        public const string APPLICATION_OCTET_STREAM = "application/octet-stream";

        /// <summary>
        /// 资源类型:表单数据(键值对)
        /// </summary>
        public const string WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";

        /// <summary>
        /// 资源类型:表单数据(键值对)。编码方式为 gb2312
        /// </summary>
        public const string WWW_FORM_URLENCODED_GB2312 = "application/x-www-form-urlencoded;charset=gb2312";

        /// <summary>
        /// 资源类型:表单数据(键值对)。编码方式为 utf-8
        /// </summary>
        public const string WWW_FORM_URLENCODED_UTF8 = "application/x-www-form-urlencoded;charset=utf-8";

        /// <summary>
        /// 资源类型:多分部数据
        /// </summary>
        public const string MULTIPART_FORM_DATA = "multipart/form-data";
    }
}

 

以上是关于模态MFC框架窗口的主要内容,如果未能解决你的问题,请参考以下文章

MFC非模态添加进程控件方法一(线程方法)

MFC 模态对话框的奇怪行为

MFC——对话框,模态对话框

MFC 如何向子窗口发送消息,子窗口是在tab control下的模态窗口?

MFC窗口和按钮事件-正向与逆向分析

MFC窗口和按钮事件-正向与逆向分析