本文整理汇总了C#中RestSharp.RestClient.DownloadData方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.DownloadData方法的具体用法?C# RestClient.DownloadData怎么用?C# RestClient.DownloadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestClient
的用法示例。
在下文中一共展示了RestClient.DownloadData方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadToFile
private async Task DownloadToFile(string url, string destinationPath)
{
var client = new RestClient(url);
var request = new RestRequest("/");
await Task.Factory.StartNew(() => client.DownloadData(request).SaveAs(destinationPath));
}
示例2: buttonCrawl_Click
private void buttonCrawl_Click(object sender, EventArgs e)
{
var client = new RestClient(_protocol + "://" + _host);
client.ClearHandlers();
client.UserAgent = _userAgent;
if (!string.IsNullOrEmpty(_cookie))
{
client.CookieContainer = ParseCookie(_cookie, _host);
}
buttonCrawl.Enabled = false;
for (var n2 = _start2; n2 <= _end2; n2++)
{
for (var n1 = _start1; n1 <= _end1; n1++)
{
var n1S = n1.ToString("D" + _pad1);
var n2S = n2.ToString("D" + _pad2);
var request = new RestRequest(_resource.Replace("#1", n1S).Replace("#2", n2S));
var path = _dir.Replace("#1", n1S).Replace("#2", n2S);
client.DownloadData(request).SaveAs(path);
if (_delay > 0)
{
Thread.Sleep(_delay);
}
}
}
buttonCrawl.Enabled = true;
}
示例3: Download
public static IRestResponse Download(RestClient client, string downloadName, string downloadLocation)
{
var request = GetDownloadRequest(downloadName);
client.DownloadData(request).SaveAs(downloadLocation);
return client.Execute(request);
}
示例4: downloadFile
private void downloadFile(object sender, MouseButtonEventArgs e)
{
int index = FilesListView.SelectedIndex;
var client = new RestClient("http://localhost:8090");
var request = new RestRequest("rest/files/" + files.ElementAt(index).id, Method.GET);
client.DownloadData(request).SaveAs(AppConfig.path_to_download + files.ElementAt(index).name);
}
示例5: GetStreamOfDeviceEvents
public void GetStreamOfDeviceEvents(string deviceId,string eventPrefix = ""){
var request = new RestRequest ("v1/devices/{deviceId}/events/{eventPrefix}");
request.AddQueryParameter ("deviceId", deviceId);
if (!String.IsNullOrEmpty (eventPrefix)) {
request.AddParameter("eventPrefix", eventPrefix);
}
request.AddQueryParameter ("access_token", AccessToken);
var encoding = ASCIIEncoding.ASCII;
var client = new RestClient (BaseUrl);
request.ResponseWriter = (responseStream) => ReadStreamForever (responseStream, encoding);
client.DownloadData (request);
}
示例6: getAttachment
// download all the attachments of a wit to the local folders
public void getAttachment(String witId, String fileAssociationId, String fileName, String userProfilepath)
{
AccessTokenDao accesstokenDao = new AccessTokenDao();
String token = accesstokenDao.getAccessToken(Common.userName);
String url = Resource.endpoint + "wittyparrot/api/attachments/associationId/" + fileAssociationId + "";
var client = new RestClient();
client.BaseUrl = new Uri(url);
var request = new RestRequest();
request.Method = Method.GET;
request.Parameters.Clear();
request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
request.RequestFormat = DataFormat.Json;
// execute the request
IRestResponse response = client.Execute(request);
if (response.ErrorException != null)
{
var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
throw myException;
}
byte[] r = client.DownloadData(request);
String fullPath = userProfilepath + "//files//attachments//";
if (!Directory.Exists(fullPath))
{
Directory.CreateDirectory(fullPath);
}
// save the file details to docs table
Docs doc = new Docs();
doc.docId = fileName.GetHashCode().ToString();
doc.localPath = fullPath;
doc.fileName = fileName;
doc.witId = witId;
AttachmentDao attachmentDao = new AttachmentDao();
attachmentDao.saveDocs(doc);
File.WriteAllBytes(fullPath + fileName, r);
}
示例7: DownloadAlbumArt
private static IPicture DownloadAlbumArt(Track reqTeack)
{
IPicture picture = null;
var client = new RestClient(reqTeack.artwork_large);
var response = client.DownloadData(new RestRequest(Method.GET));
if (response == null)
{
MessageBox.Show("Album art download failed", "An error occured", MessageBoxButton.OK);
Environment.Exit(-1);
/*
picture = null;
*/
}
else
{
picture = new Picture(new ByteVector(response));
}
return picture;
}
示例8: DownloadPillboxImage
public static string DownloadPillboxImage(string rxcui)
{
var id = FindPillBoxImage(rxcui);
if(string.IsNullOrWhiteSpace(id)) {
return null;
}
var client = new RestClient("http://pillbox.nlm.nih.gov/assets/medium/");
var request = new RestRequest(string.Format("{0}md.jpg", id));
var response = client.DownloadData(request);
if(response == null) {
return null;
}
var path = Path.Combine(MyDocuments.FullName, rxcui + ".jpg");
File.WriteAllBytes(path, response);
return path;
}
示例9: DumpFile
public IDataResponse DumpFile(IMemberData data, string outputFolder, string authToken)
{
IDataResponse dataResponse = null;
try
{
if (!string.IsNullOrEmpty(FileDumpUrl))
{
//added this to be able to get files with ASCII characters in them.
Byte[] encodedBytes = System.Text.Encoding.ASCII.GetBytes(data.Path);
string newPath = System.Text.Encoding.ASCII.GetString(encodedBytes);
string pathString = string.Concat(@"{""path"":""", newPath, @"""}");
string url = string.Format("{0}/{1}/", _baseUrl, _apiVersion);
RestClient client = new RestClient(url);
RestRequest request = new RestRequest(FileDumpUrl, Method.GET);
client.UserAgent = UserAgentVersion;
//add headers, include user authentication we pass in with admin privileges
request.AddHeader("Authorization", "Bearer " + authToken);
request.AddHeader("Dropbox-API-Select-User", data.MemberId);
request.AddHeader("Dropbox-API-Arg", pathString);
//download file by using raw bytes returned
byte[] jsonResponseDump = client.DownloadData(request);
// strip out email prefix as folder name.
int index = data.Email.IndexOf("@");
string folderName = data.Email.Substring(0, index);
if (!data.ZipFiles)
{
//get the Dropbox folder structure so we can recreate correct folder structure locally under user folder below
String dbdirName = Path.GetDirectoryName(data.Path);
dbdirName = dbdirName.Remove(0, 1);
//combine Dropbox subdirectory to email username
if (!string.IsNullOrEmpty(dbdirName))
{
folderName = folderName + "\\" + dbdirName;
}
string fullOutputFolder = Path.Combine(outputFolder, folderName);
if (!Directory.Exists(fullOutputFolder))
{
Directory.CreateDirectory(fullOutputFolder);
}
string outputPath = Path.Combine(fullOutputFolder, data.FileName);
File.WriteAllBytes(outputPath, jsonResponseDump);
}
//Added 5/5/16 - Zip file if needed. If first file create the zipfile, if not just add to existing zip file
if (data.ZipFiles)
{
string fullOutputFolder = Path.Combine(outputFolder, folderName);
if (!Directory.Exists(fullOutputFolder))
{
Directory.CreateDirectory(fullOutputFolder);
}
string outputPath = Path.Combine(fullOutputFolder, data.FileName);
File.WriteAllBytes(outputPath, jsonResponseDump);
string dateString = DateTime.Now.ToString("-M.dd.yyyy");
string zipName = Path.Combine(fullOutputFolder, (folderName + dateString + ".zip"));
if (File.Exists(zipName))
{
using (ZipArchive modFile = ZipFile.Open(zipName, ZipArchiveMode.Update))
{
modFile.CreateEntryFromFile(outputPath, data.FileName, CompressionLevel.Fastest);
}
}
if (!File.Exists(zipName))
{
using (ZipArchive newFile = ZipFile.Open(zipName, ZipArchiveMode.Create))
{
newFile.CreateEntryFromFile(outputPath, data.FileName, CompressionLevel.Fastest);
}
}
File.Delete(outputPath);
}
}
}
catch (Exception e)
{
dataResponse = new DataResponse(HttpStatusCode.InternalServerError, e.Message, null);
}
return dataResponse;
}
示例10: Download_File
public void Download_File(string fileId, string fileName)
{
var client = new RestClient(UrlClient);
var request = new RestRequest("rest/files/" + fileId, Method.GET);
client.DownloadData(request).SaveAs(DownloadPath + fileName);
MessageBox.Show("Descargado correctamente!");
}
示例11: TestStreaming
public void TestStreaming()
{
string tempFile = Path.GetTempFileName();
using (var writer = File.OpenWrite(tempFile))
{
var client = new RestClient("baseUrl");
var request = new RestRequest("Assets/LargeFile.7z");
request.ResponseWriter = (responseStream) => responseStream.CopyTo(writer);
var response = client.DownloadData(request);
}
}
示例12: TestDownload
public void TestDownload()
{
var client = new RestClient("url");
var request = new RestRequest("/", Method.GET);
client.DownloadData(request).SaveAs("path");
}
示例13: Download
/// <summary>
/// Use public id to call Box.net and return file specified.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public ActionResult Download(int id)
{
var client = new RestClient(DownloadUrl);
var request = new RestRequest
{
Resource = string.Format("{0}/{1}/{2}", "download", _boxAuthToken, id)
};
//TODO: Make call to get real file name.
var downloadedBytes = client.DownloadData(request);
return File(downloadedBytes, "text/plain", "file.txt");
}
示例14: DecryptDump
byte[] DecryptDump(byte[] encBin)
{
RestClient client = new RestClient("https://www.socram.ovh/amiibo/");
RestRequest request = new RestRequest("api.php", Method.POST);
request.AddParameter("MAX_FILE_SIZE", 540);
request.AddParameter("operation", "decrypt");
request.AddFileBytes("dump", encBin, @"Dump.bin");
return client.DownloadData(request);
}