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


C# HttpWebResponse.Close方法代码示例

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


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

示例1: DisposeObject

 private static void DisposeObject(ref HttpWebRequest request, ref HttpWebResponse response,
     ref Stream responseStream, ref StreamReader reader)
 {
     if (request != null)
     {
         request = null;
     }
     if (response != null)
     {
         response.Close();
         response = null;
     }
     if (responseStream != null)
     {
         responseStream.Close();
         responseStream.Dispose();
         responseStream = null;
     }
     if (reader != null)
     {
         reader.Close();
         reader.Dispose();
         reader = null;
     }
 }
开发者ID:superhappy123,项目名称:Test,代码行数:25,代码来源:WebUrlRead.cs

示例2: ConnectionAvailable

 public bool ConnectionAvailable()
 {
     try
     {
         req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
         resp = (HttpWebResponse)req.GetResponse();
         if (HttpStatusCode.OK == resp.StatusCode)
         {
             // HTTP = 200 - Интернет безусловно есть!
             resp.Close();
             return true;
         }
         else
         {
             // сервер вернул отрицательный ответ, возможно что инета нет
             resp.Close();
             return false;
         }
     }
     catch (WebException)
     {
         // Ошибка, значит интернета у нас нет. Плачем :'(
         return false;
     }
 }
开发者ID:hardor,项目名称:easytrain,代码行数:25,代码来源:parse.cs

示例3: displayHttpWebReponse

 /// <summary>
 /// Outputs the HTTP reponse to the console
 /// 
 /// Code taken from http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx
 /// </summary>
 /// <param name="response"></param>       
 private static void displayHttpWebReponse(HttpWebResponse response)
 {
     Console.WriteLine(response.StatusCode);
     Stream receiveStream = response.GetResponseStream();
     Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
     // Pipes the stream to a higher level stream reader with the required encoding format.
     StreamReader readStream = new StreamReader(receiveStream, encode);
     Console.WriteLine("\r\nResponse stream received.");
     Char[] read = new Char[256];
     // Reads 256 characters at a time.
     int count = readStream.Read(read, 0, 256);
     Console.WriteLine("HTML...\r\n");
     while (count > 0)
     {
         // Dumps the 256 characters on a string and displays the string to the console.
         String str = new String(read, 0, count);
         Console.Write(str);
         count = readStream.Read(read, 0, 256);
     }
     Console.WriteLine("");
     // Releases the resources of the response.
     response.Close();
     // Releases the resources of the Stream.
     readStream.Close();
 }
开发者ID:fatman2021,项目名称:piwik-dotnet-tracker,代码行数:31,代码来源:PiwikTrackerSamples.cs

示例4: Login

        public Login(string Username, string Password)
        {
            string url = string.Format("http://www.myfitnesspal.com/account/login");
            request = (HttpWebRequest)WebRequest.Create(url);

            request.AllowAutoRedirect = false;
            request.CookieContainer = new CookieContainer();

            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            string NewValue = string.Format("username={0}&password={1}&remember_me=1",Username,Password);
            request.ContentLength = NewValue.Length;
            // Write the request
            StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(NewValue);
            stOut.Close();
            // Do the request to get the response
            response = (HttpWebResponse)request.GetResponse();
            StreamReader stIn = new StreamReader(response.GetResponseStream());

            string strResponse = stIn.ReadToEnd();
            stIn.Close();

            cookies = request.CookieContainer;
            response.Close();
        }
开发者ID:PCurd,项目名称:MyFitnessPalApp,代码行数:26,代码来源:Login.cs

示例5: WebResponse

    public WebResponse(HttpWebRequest request, HttpWebResponse response)
    {
      _requestContentType = request == null ? null : request.ContentType;
      _response = response;
      _headers = new NameValueDictionary(response == null
        ? new System.Collections.Specialized.NameValueCollection()
        : response.Headers);

      _content = new MemoryStream();
      if (_response != null)
      {
        using (var stream = _response.GetResponseStream())
        {
          stream.CopyTo(_content);
        }
        _content.Position = 0;
        _response.Close();
      }

#if !NET4
      if (request.CookieContainer != null && response.Cookies.Count > 0)
      {
        request.CookieContainer.BugFix_CookieDomain();
      }
#endif
    }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:26,代码来源:WebResponse.cs

示例6: GetResponseContent

		public string GetResponseContent(HttpWebResponse response)
		{
			if (response == null)
			{
				throw new ArgumentNullException("response");
			}

			string responseFromServer = null;

			try
			{
				// Get the stream containing content returned by the server.
				using (Stream dataStream = response.GetResponseStream())
				{
					// Open the stream using a StreamReader for easy access.
					using (StreamReader reader = new StreamReader(dataStream))
					{
						// Read the content.
						responseFromServer = reader.ReadToEnd();
						// Cleanup the streams and the response.
					}
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
			finally
			{
				response.Close();
			}
			LastResponse = responseFromServer;
			return responseFromServer;
		}
开发者ID:annafeldman,项目名称:MatterControl,代码行数:34,代码来源:RequestManager.cs

示例7: GetResponseAsString

        private static string GetResponseAsString(HttpWebResponse rsp, Encoding encoding)
        {
            Stream stream = null;
            StreamReader reader = null;

            try {
                // 以字符流的方式读取HTTP响应
                stream = rsp.GetResponseStream();
                switch (rsp.ContentEncoding) {
                    case "gzip":
                        stream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress);
                        break;

                    case "deflate":
                        stream = new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionMode.Decompress);
                        break;
                }
                reader = new StreamReader(stream, encoding);

                return reader.ReadToEnd();
            }
            finally {
                // 释放资源
                if (reader != null) reader.Close();
                if (stream != null) stream.Close();
                if (rsp != null) rsp.Close();
            }
        }
开发者ID:noikiy,项目名称:WechatEmulation,代码行数:28,代码来源:NetHelper.cs

示例8: Reporttoserver

 public string Reporttoserver(string status, string testname, ref string error, string emailaddress)
 {
    vartestname = testname;
    varstatus = status;
    varerror = error;
    count += 1;
    if(status == "Complete" && emailaddress.Length > 5)
        email(emailaddress);
    string responsestring = ".";
     try
     {
         req = (HttpWebRequest)WebRequest.Create("http://nz-hwlab-ws1:80/dashboard/update/?script=" + testname + "&status=" + status); //Complete
         resp = (HttpWebResponse)req.GetResponse();
         Stream istrm = resp.GetResponseStream();
         int ch;
         for (int ij = 1; ; ij++)
         {
             ch = istrm.ReadByte();
             if (ch == -1) break;
             responsestring += ((char)ch);
         }
         resp.Close();
         //email();
         return responsestring + " : from server";
     }
     catch (System.Net.WebException e)
     {
         error = e.Message;
         System.Console.WriteLine(error);
         string c = count.ToString();
         return "ServerError " + c;
     }
 }
开发者ID:kalaharileeu,项目名称:PylauncherFSI,代码行数:33,代码来源:Report.cs

示例9: GetRemoteResponse

        public static HttpRemoteResponse GetRemoteResponse(HttpWebResponse webResponse)
        {
            HttpRemoteResponse response = new HttpRemoteResponse(webResponse.StatusCode,
                GetHeadersDictionaryFrom(webResponse.Headers),
                GetContentFromStream(webResponse.GetResponseStream()));

            webResponse.Close();
            return response;
        }
开发者ID:sharpshooting,项目名称:restfulie-csharp,代码行数:9,代码来源:HttpRemoteResponseFactory.cs

示例10: GetRawStringFromResponse

        private string GetRawStringFromResponse(HttpWebResponse response)
        {
            using (var sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                var responseString = sr.ReadToEnd();
                response.Close();

                return responseString;
            }
        }
开发者ID:br4mbor,项目名称:WattCountdown,代码行数:10,代码来源:Watt.cs

示例11: DisplayResponse

 private static void DisplayResponse(HttpWebResponse hresp, string id)
 {
     Trace.WriteLine(null);
     Trace.WriteLine("*** Response Start ***");
     Trace.WriteLine(hresp.StatusCode);
     Trace.WriteLine(hresp.StatusDescription);
     DisplayHeaders(hresp.Headers);
     DisplayContent(hresp, id);
     hresp.Close();
     Trace.WriteLine("*** Response End ***");
     Trace.WriteLine("");
 }
开发者ID:HaleLu,项目名称:GetPic,代码行数:12,代码来源:Form1.cs

示例12: Response

 public Response(HttpWebResponse response, string Format)
 {
     if (Format == "xml")
     {
         responseFormat = Format;
     }
     else {
         responseFormat = "json";
     }
     setResponseBody(response);
     response.Close();
 }
开发者ID:zencoder,项目名称:zencoder-dotnet,代码行数:12,代码来源:Response.cs

示例13: printResponseToConsole

        protected static void printResponseToConsole(HttpWebResponse response)
        {
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            String responseXml = reader.ReadToEnd();

            Console.Out.WriteLine("BlueTarp Auth status code: " + response.StatusCode);
            Console.Out.WriteLine("BlueTarp Auth Response:");
            Console.Out.WriteLine(responseXml);
            dataStream.Close();
            reader.Close();
            response.Close();
        }
开发者ID:BlueTarp,项目名称:auth-csharp,代码行数:13,代码来源:ExampleBase.cs

示例14: deleteRecording

        /*
         * Method: deleteRecording()
         * Summary: Attempts to delete a recording from the server
         * Parameter: recJson - A recording string in the JSON format
         * Returns: True or false depending on the success of the delete operation
         */
        public static bool deleteRecording(string recJson)
        {
            // Prepare the DELETE HTTP request to the recordings endpoint
            prepareRequest(recordingUrl, "text/json", "DELETE");

            //RecordingManager recording = new RecordingManager(recJson);
            bool result = false;

            try
            {
                // Extract the ID from the recJson string
                string recId = RecordingManager.getRecId(recJson);

                // Create the JSON object to be written to the server
                JObject recInfo = new JObject(
                    new JProperty("recId", recId),
                    new JProperty("UserId", Properties.Settings.Default.currentUser));

                // Write the JSON string to the server
                using (var writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(recInfo.ToString());
                    writer.Flush();
                    writer.Close();
                }

                try
                {
                    // Retrieve the response
                    response = (HttpWebResponse)request.GetResponse();

                    // If the response code is "OK", return true
                    if (response.StatusCode == HttpStatusCode.OK)
                        result = true;
                    response.Close();
                }
                catch (WebException we)
                {
                    Console.WriteLine(we.Message);
                    return false;
                }
            }

            catch (WebException we)
            {
                Console.WriteLine(we.Message);
                result = false;
            }

            return result;
        }
开发者ID:Briscoooe,项目名称:SequenceAutomationProject,代码行数:57,代码来源:ConnectionManager.cs

示例15: GetContentForResponse

        public static String GetContentForResponse(HttpWebResponse response)
        {
            Stream stream = response.GetResponseStream();

            String characterSet = String.IsNullOrEmpty(response.CharacterSet) ? "UTF-8" : response.CharacterSet;
            Encoding encoding = Encoding.GetEncoding(characterSet);

            StreamReader reader = new StreamReader(stream, encoding);
            String htmlContent = reader.ReadToEnd();

            stream.Close();
            response.Close();

            return htmlContent;
        }
开发者ID:wrobeseb,项目名称:parRobot,代码行数:15,代码来源:HtmlUtils.cs


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