本文整理汇总了C#中System.Net.WebClient.DownloadData方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.DownloadData方法的具体用法?C# System.Net.WebClient.DownloadData怎么用?C# System.Net.WebClient.DownloadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了System.Net.WebClient.DownloadData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
String pageIDString = context.Request.QueryString["PageID"] as String;
if (pageIDString == null) return;
String heightString = context.Request.QueryString["h"] as String;
String widthString = context.Request.QueryString["w"] as String;
int height;
int width;
if (!Int32.TryParse(heightString, out height)) height = 300;
if (!Int32.TryParse(widthString, out width)) width = 200;
int pageID;
if (Int32.TryParse(pageIDString, out pageID))
{
BHLProvider provider = new BHLProvider();
PageSummaryView ps = provider.PageSummarySelectByPageId(pageID);
String imageUrl = String.Empty;
if (ps.ExternalURL == null)
{
String cat = (ps.WebVirtualDirectory == String.Empty) ? "Researchimages" : ps.WebVirtualDirectory;
String item = ps.MARCBibID + "/" + ps.BarCode + "/jp2/" + ps.FileNamePrefix + ".jp2";
imageUrl = String.Format("http://images.mobot.org/ImageWeb/GetImage.aspx?cat={0}&item={1}&wid=" + width.ToString() + "&hei= " + height.ToString() + "&rgn=0,0,1,1&method=scale", cat, item);
}
else
{
imageUrl = ps.ExternalURL;
}
System.Net.WebClient client = new System.Net.WebClient();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(client.DownloadData(imageUrl));
}
}
示例2: getCoordinates
public static decimal[] getCoordinates(string address1, string address2,
string city, string state, string zipcode, string appId)
{
string retVal;
decimal[] coordinates = new decimal[2];
System.Net.WebClient webClient = new System.Net.WebClient();
string request = "http://where.yahooapis.com/geocode?location="
+ address1 + "+" + address2 + "+" + city + "+" + state + "+" + zipcode
+ "&" + appId;
byte[] responseXML;
try
{
responseXML = webClient.DownloadData(request);
System.Text.UTF8Encoding objUTF8 = new System.Text.UTF8Encoding();
retVal = objUTF8.GetString(responseXML) + "\n";
}
catch (System.Exception ex)
{
retVal = ex.Message;
}
// parse the return values
XmlDocument xml = new XmlDocument();
xml.LoadXml(retVal);
XmlNode ndLatitude = xml.SelectSingleNode("//latitude");
XmlNode ndLongitude = xml.SelectSingleNode("//longitude");
coordinates[0] = Convert.ToDecimal(ndLatitude.InnerText);
coordinates[1] = Convert.ToDecimal(ndLongitude.InnerText);
return coordinates;
}
示例3: getXMLDocument
private string getXMLDocument(string url)
{
// Grab the body of xml document from its source
System.Net.WebClient wc = new System.Net.WebClient();
byte[] webData = wc.DownloadData(url);
// Get the downloaded data into a form suitable for XML processing
char[] charData = new char[webData.Length];
for (int i = 0; i < charData.Length; i++)
{
charData[i] = (char)webData[i];
}
string xmlStr = new String(charData);
// Clean up the document (first "<" and last ">" and everything in between)
int start = xmlStr.IndexOf("<", 0, xmlStr.Length - 1);
int length = xmlStr.LastIndexOf(">") - start + 1;
// Return only the XML document parts
return xmlStr.Substring(start, length);
}
示例4: MainWindow
public MainWindow()
{
InitializeComponent();
// 以下を追加
this.btnDownload.Click += (sender, e) =>
{
var client = new System.Net.WebClient();
byte[] buffer = client.DownloadData("http://k-db.com/?p=all&download=csv");
string str = Encoding.Default.GetString(buffer);
string[] rows = str.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
// 1行目をラベルに表示
this.lblTitle.Content = rows[0];
// 2行目以下はカンマ区切りから文字列の配列に変換しておく
List<string[]> list = new List<string[]>();
rows.ToList().ForEach(row => list.Add(row.Split(new char[] { ',' })));
// ヘッダの作成(データバインド用の設計)
GridView view = new GridView();
list.First().Select((item, cnt) => new { Count = cnt, Item = item }).ToList().ForEach(header =>
{
view.Columns.Add(
new GridViewColumn()
{
Header = header.Item,
DisplayMemberBinding = new Binding(string.Format("[{0}]", header.Count))
});
});
// これらをリストビューに設定
lvStockList.View = view;
lvStockList.ItemsSource = list.Skip(1);
};
}
示例5: GetBinaryFromURL
internal byte[] GetBinaryFromURL(string URL)
{
LogProvider.LogMessage(string.Format("Url.GetBinaryFromURL - '{0}'", URL));
string cacheKey = string.Format("GetBinaryFromURL_{0}", URL);
var cached = CacheProvider.Get<byte[]>(cacheKey);
if (cached != null)
{
LogProvider.LogMessage("Url.GetBinaryFromURL : Returning cached result");
return cached;
}
LogProvider.LogMessage("Url.GetBinaryFromURL : Cached result unavailable, fetching url content");
var webClient = new System.Net.WebClient();
byte[] result;
try
{
result = webClient.DownloadData(URL);
}
catch (Exception error)
{
if (LogProvider.HandleAndReturnIfToThrowError(error))
throw;
return null;
}
CacheProvider.Set(result, cacheKey);
return result;
}
示例6: ResizeImage
public override bool ResizeImage(string sourceImagePath, Size newSize)
{
var fileurl = this._imageFile.GetImageUrl(sourceImagePath);
System.Net.WebClient net = new System.Net.WebClient();
var file = net.DownloadData(fileurl);
var newstream = this._imageFile.ResizeImage(file, newSize.Width, newSize.Height);
this._imageFile.UpdateImageFile(newstream, sourceImagePath);
var model = DB.GetModelByHash(sourceImagePath);
model.Size = (int)newstream.Length;
var size = Dev.Comm.ImageHelper.GetImageSize(newstream);
model.Width = size.Width;
model.Height = size.Height;
DB.UpdateModel(model);
return true;
}
示例7: Go
public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats)
{
System.Net.WebClient wc = new System.Net.WebClient();
try
{
byte[] r = wc.DownloadData(this.RSS.URL);
if ((r == null) || (r.Length == 0))
{
this.Error = true;
this.ErrorText = "No data downloaded";
this.Done = true;
return false;
}
string saveTemp = Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + settings.FilenameFriendly(this.RSS.Title);
if (new FileInfo(saveTemp).Extension.ToLower() != "torrent")
saveTemp += ".torrent";
File.WriteAllBytes(saveTemp, r);
System.Diagnostics.Process.Start(settings.uTorrentPath, "/directory \"" + (new FileInfo(this.TheFileNoExt).Directory.FullName) + "\" \"" + saveTemp + "\"");
this.Done = true;
return true;
}
catch (Exception e)
{
this.ErrorText = e.Message;
this.Error = true;
this.Done = true;
return false;
}
}
示例8: readOCR
public static string readOCR (Uri ocr_url) {
AzureSearchServiceController checkUrl = new AzureSearchServiceController();
string ocrPrevText = "";
if (checkUrl.RemoteFileExists(ocr_url.ToString()))
{
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData(ocr_url);
string webData = System.Text.Encoding.UTF8.GetString(raw);
string[] ocrSplit = webData.Split(' ');
for (int i = 0; i < 300; i++)
{
ocrPrevText += ocrSplit[i];
ocrPrevText += " ";
}
return ocrPrevText;
}
else
{
ocrPrevText ="Unfortunately OCR is not available for this document";
} return ocrPrevText;
}
示例9: EncryptionButtonInValidateCard_Click
protected void EncryptionButtonInValidateCard_Click(object sender, EventArgs e)
{
Uri baseUri = new Uri("http://webstrar49.fulton.asu.edu/page3/Service1.svc");
UriTemplate myTemplate = new UriTemplate("encrypt?plainText={plainText}");
String plainText = PlainText_TextBox1.Text;
Uri completeUri = myTemplate.BindByPosition(baseUri, plainText);
System.Net.WebClient webClient = new System.Net.WebClient();
byte[] content = webClient.DownloadData(completeUri);
//EncryptionService.Service1Client encryptionClient = new EncryptionService.Service1Client();
// String cipher=encryptionClient.encrypt(plainText);
String contentinString = Encoding.UTF8.GetString(content, 0, content.Length);
String pattern = @"(?<=\>)(.*?)(?=\<)";
Regex r = new Regex(pattern);
Match m = r.Match(contentinString);
String cipher = "";
if (m.Success)
{
cipher = m.Groups[1].ToString();
}
cipherTextBox.Enabled = true;
cipherTextBox.Text = cipher;
cipherTextBox.Enabled = false;
}
示例10: GetDonationDriveFromWeb
public static string GetDonationDriveFromWeb()
{
string sourceUrl = ConfigurationManager.AppSettings["JsDataSourceUrl"];
using (var wc = new System.Net.WebClient())
using (MemoryStream stream = new MemoryStream(wc.DownloadData(sourceUrl)))
return Encoding.UTF8.GetString(stream.ToArray());
}
示例11: Download
public static Stream Download(this Uri url)
{
using (var webClient = new System.Net.WebClient())
{
var data = webClient.DownloadData(url);
return new MemoryStream(data);
}
}
示例12: Return
public ActionResult Return(string rid, string SPListId, string documentName, string SPSource, string SPListURLDir)
{
// Get the tokens
string spAppToken = Request.Cookies["SPAppToken"].Value;
string spHostURL = Request.Cookies["SPHostURL"].Value;
using (var client = new DocumentEndPointClient())
{
var getStatusResponse = client.getStatus(new getstatusrequest
{
password = PASSWORD,
service = SERVICE,
requestid = new string[] { rid }
});
// If there's no signature result available, we assume it's been cancelled
// and just send the user back to the document list he/she came from
if (getStatusResponse.First().documentstatus == null)
{
return Redirect(SPSource);
}
// Otherwise, we get the URI to the SDO (signed document object)
string resultUri = getStatusResponse.First().documentstatus.First().resulturi;
// Let's just use an old school HTTP WebClient with Basic authentication
// to download the signed document from Signicat Session Data Storage
byte[] sdo;
string contentType;
using (var webClient = new System.Net.WebClient())
{
webClient.Credentials = new System.Net.NetworkCredential(SERVICE, PASSWORD);
sdo = webClient.DownloadData(resultUri);
contentType = webClient.ResponseHeaders["Content-Type"];
}
// Now, let's upload it to the same document list as the original
SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(spAppToken, Request.Url.Authority);
string accessToken = TokenHelper.GetAccessToken(contextToken, new Uri(spHostURL).Authority).AccessToken;
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(spHostURL.ToString(), accessToken))
{
if (clientContext != null)
{
List list = clientContext.Web.Lists.GetById(Guid.Parse(SPListId));
var fileCreationInformation = new FileCreationInformation
{
Content = sdo,
Overwrite = true,
Url = spHostURL + SPListURLDir + "/" + documentName + " - SIGNED" + GetFileExtensionForContentType(contentType)
};
var uploadFile = list.RootFolder.Files.Add(fileCreationInformation);
uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();
}
}
}
return Redirect(SPSource);
}
示例13: getImageAsBitmap
public static Bitmap getImageAsBitmap(this Uri uri)
{
var webClient = new System.Net.WebClient();
var imageBytes = webClient.DownloadData(uri);
"image size :{0}".info(imageBytes.size());
var memoryStream = new MemoryStream(imageBytes);
var bitmap = new Bitmap(memoryStream);
return bitmap;
}
示例14: ToStream
public static Stream ToStream(this Uri url)
{
byte[] imageData = null;
using (var wc = new System.Net.WebClient())
imageData = wc.DownloadData(url);
return new MemoryStream(imageData);
}
示例15: GetMenu
public static string GetMenu(string accessToken)
{
using (var wc = new System.Net.WebClient())
{
var url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accessToken;
var res = wc.DownloadData(url);
return Utities.GetStringFromBytes(res);
}
}