当前位置: 首页>>代码示例>>C#>>正文


C# WebRequest.EndGetResponse方法代码示例

本文整理汇总了C#中WebRequest.EndGetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.EndGetResponse方法的具体用法?C# WebRequest.EndGetResponse怎么用?C# WebRequest.EndGetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebRequest的用法示例。


在下文中一共展示了WebRequest.EndGetResponse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: runNetLoop

    public void runNetLoop()
    {
        ManualResetEvent http_response_sync = new ManualResetEvent(false);
        HttpWebResponse resp = null;

        int registeredHandle = 0;
        try
        {
            conn = HttpWebRequest.Create(url);//todomt (HttpConnection)Connector.open(url);
            //System.Net.ServicePointManager.Expect100Continue = false;

            if (method == 0) conn.Method = "GET";
            else conn.Method = "POST";

            if (updateTime != null && updateTime.Trim().Length > 0) {
                conn.Headers["IfModifiedSince"] = updateTime;
            }

            registeredHandle = CRunTime.registerObject(conn);

        }
        catch (Exception e)
        {
            quit = true;
            Logger.log(e.ToString());
            UIWorker.addUIEventLog("Async Net : Exception opening URL " + e);
        }

        int handle = registeredHandle;

        UIWorker.addUIEventValid(c_do_async_connect_cb, handle, cb_addr, context, 0, false, this);
        if (quit) return;

        while (!quit)
        {
            lock (conn)
            {
                if (!do_read)
                {
                    try
                    {
                        Monitor.Wait(conn);
                    }
                    catch (SynchronizationLockException e)
                    {
                    }
                    if (quit) return;
                    if (!do_read) continue;
                }
            }

            try
            {
                if (Stream == null)
                {
                    resp = null;
                    Exception exp = null;
                    try
                    {
                        http_response_sync.Reset();
                        conn.BeginGetResponse(delegate(IAsyncResult result)
                        {
                            try
                            {
                                Logger.log("downloading " + conn.RequestUri);
                                resp = (HttpWebResponse)conn.EndGetResponse(result);
                                http_response_sync.Set();
                            }
                            catch (Exception we)
                            {
                                resp = null;
                                exp = we;
                                http_response_sync.Set();
                            }
                        }, null);
                    }
                    catch (Exception ioe)
                    {
                        resp = null;
                        exp = ioe;
                        http_response_sync.Set();
                    }

                    http_response_sync.WaitOne();

                    if (resp != null)
                    {
                        Stream = resp.GetResponseStream();
                        int status = (int)resp.StatusCode;
                        long data_size = resp.ContentLength;
                        string lastModifiedStr = resp.Headers["Last-Modified"];
                        //Logger.log("Java header, s is " + lastModifiedStr);

                        /*
                         * We need to send c a complete header string, so we fake it by creating the
                         * res string. More header fields can be added later on besides the content length and last-modified
                         *
                         */
                        string res = "HTTP/1.1 " + status + " OK\r\nContent-Length: " + data_size + "\r\n";
                        if (lastModifiedStr != null)
//.........这里部分代码省略.........
开发者ID:EranGon,项目名称:WazeWP7,代码行数:101,代码来源:AsyncNet.cs


注:本文中的WebRequest.EndGetResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。