本文整理汇总了C#中System.Net.WebResponse.Close方法的典型用法代码示例。如果您正苦于以下问题:C# WebResponse.Close方法的具体用法?C# WebResponse.Close怎么用?C# WebResponse.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebResponse
的用法示例。
在下文中一共展示了WebResponse.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckURL
public bool CheckURL(string url)
{
ourUri = new Uri(url);
myWebRequest = WebRequest.Create(url);
try
{
myWebResponse = myWebRequest.GetResponse();
}
catch
{
myWebResponse.Close();
return false;
}
myWebResponse.Close();
return true;
}
示例2: Read
/// <include file='doc\TextReturnReader.uex' path='docs/doc[@for="TextReturnReader.Read"]/*' />
public override object Read(WebResponse response, Stream responseStream) {
try {
string decodedString = RequestResponseUtils.ReadResponse(response);
return matcher.Match(decodedString);
}
finally {
response.Close();
}
}
示例3: S3Response
private S3Response(WebResponse response)
{
this.response = response;
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream);
this.responseString = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
response.Close();
}
示例4: DownloadImage
private void DownloadImage(WebResponse response, string url)
{
using (Stream stream = response.GetResponseStream())
{
var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
var data = memoryStream.ToArray();
AddImageCache(url, data);
}
response.Close();
}
示例5: ExecutionResult
/// <summary>
/// Constructor
/// </summary>
/// <param name="response">Response of type System.Net.WebResponse</param>
internal ExecutionResult(System.Net.WebResponse response)
{
this.status = ((HttpWebResponse)response).StatusDescription;
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
this.response = response;
response.Close();
}
示例6: GetdataByStates
private void GetdataByStates(IAsyncResult result)
{
response = request.EndGetResponse(result);
StreamReader sd = new StreamReader(response.GetResponseStream());
JsonReader jreader = new JsonTextReader(sd);
JsonSerializer se = new JsonSerializer();
Dictionary<string, object> GetdataState = se.Deserialize<Dictionary<string, object>>(jreader);
dataList = DataStatebyvotes(GetdataState);
response.Close();
sd.Close();
global.my_flag = 1;
}
示例7: CloseQuietly
public static void CloseQuietly(WebResponse response)
{
try
{
if (response != null)
{
response.Close();
}
}
catch (Exception ex)
{
log.Warn(response, ex);
}
}
示例8: getLyrics
public string[] getLyrics(String author, String songName)
{
string[] result = null;
try
{
request = WebRequest.Create(createURL(author, songName));
response = request.GetResponse();
String lyrics = "";
//now do crawling
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
doc.LoadHtml(reader.ReadToEnd());
lyrics = doc.DocumentNode.SelectSingleNode(Assets.DIV_NAME).InnerText;
foreach (HtmlNode node in doc.DocumentNode.SelectSingleNode(Assets.DIV_LYRICS).ChildNodes)
{
lyrics += node.InnerText;
lyrics += "\n\n";
}
}
response.Close();
String parts = "";
HtmlNode partnode = doc.DocumentNode.SelectSingleNode(Assets.PLUS_INFO);
foreach (HtmlNode node in partnode.Elements(Assets.P_TAG))
{
parts += node.InnerText + "\n\n";
}
result = new string[4];
result[0] = doc.DocumentNode.SelectSingleNode(Assets.IMAGE_XPATH).Attributes[Assets.SRC_ATTR].Value;
result[1] = lyrics;
result[2] = parts;
result[3] = "\n\nSource:Metro Lyrics";
}
catch
{
}
return result;
}
示例9: Read
public override object Read(WebResponse response, Stream responseStream)
{
object obj2;
try
{
string text = RequestResponseUtils.ReadResponse(response);
obj2 = this.matcher.Match(text);
}
finally
{
response.Close();
}
return obj2;
}
示例10: ParseResponseStreamToText
public static string ParseResponseStreamToText(WebResponse response)
{
try
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string robotsTxt = reader.ReadToEnd();
response.Close();
reader.Close();
return robotsTxt;
}
catch (Exception ex)
{
throw new Exception("An error occurred while I try to read Response Stream :(", ex);
}
}
示例11: Save
public bool Save( string ImagePath, string ImageURL){
if (! Directory.Exists(ImagePath))
Directory.CreateDirectory(ImagePath);
string ImageName = Path.GetFileName(ImageURL);
// Read image as byte array
try
{
RequestToImage = (HttpWebRequest) WebRequest.Create(ImageURL);
ImageResponse = RequestToImage.GetResponse();
ResponseStream = ImageResponse.GetResponseStream();
BinaryReader = new BinaryReader(ResponseStream);
Image = BinaryReader.ReadBytes(500000);
}
catch (IOException) { MessageBox.Show("Failed to load image."); }
finally
{
BinaryReader.Close();
ResponseStream.Close();
ImageResponse.Close();
}
// Write image to file
FileStream = new FileStream(ImagePath + ImageName, FileMode.Create);
BinaryWriter = new BinaryWriter(FileStream);
try
{
BinaryWriter.Write(Image);
}
catch (IOException) { MessageBox.Show("Failed to save image."); }
finally
{
FileStream.Close();
BinaryWriter.Close();
}
this.ImagePath = ImagePath + ImageName;
return File.Exists(this.ImagePath);
}
示例12: Start
// Use this for initialization
void Start()
{
//test first, need to use linq.
request = HttpWebRequest.Create("http://io.adafruit.com/api/feeds.json");
request.Headers.Add("X-AIO-Key", KeyManager.key);
response = request.GetResponse();
Debug.Log(response);
Debug.Log(response.GetResponseStream());
Stream data = response.GetResponseStream();
StreamReader reader = new StreamReader(data);
string responseFromServer = reader.ReadToEnd();
reader.Close();
data.Close();
response.Close();
Debug.Log(responseFromServer);
ArrayList decoded = (ArrayList) JSON.JsonDecode(responseFromServer);
Debug.Log(decoded.Count);
Debug.Log(((Hashtable)decoded[0])["key"]);
Feed f = new Feed((Hashtable)decoded[0]);
Debug.Log(f.name);
}
示例13: GetXpathDocumentFromResponse
protected virtual XPathNavigator GetXpathDocumentFromResponse(WebResponse response)
{
using (var stream = response.GetResponseStream())
{
if (stream == null) throw new InvalidOperationException("Response Stream is null");
try
{
return new XPathDocument(stream).CreateNavigator();
}
catch (XmlException exception)
{
throw new XmlException("Could not read HTTP Response as XML", exception);
}
finally
{
response.Close();
}
}
}
示例14: removeBT_Click
private void removeBT_Click(object sender, RoutedEventArgs e) //Removes a file
{
try
{
//it is assumed that the address points to a file and not a directory
ftpRequest = (FtpWebRequest)WebRequest.Create(address + directory + lstDir.SelectedItem.ToString());
ftpRequest.Credentials = new NetworkCredential(c_username, c_password);
ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
}
catch
{
MessageBox.Show("could not delete file: " + directory);
}
ftpResponse.Close();
ftpResponse = null;
refresh(lstDir);
}
示例15: Read
public override object Read(WebResponse response, Stream responseStream)
{
response.Close();
return null;
}