本文整理汇总了C#中System.Net.WebClient.UploadValues方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.UploadValues方法的具体用法?C# System.Net.WebClient.UploadValues怎么用?C# System.Net.WebClient.UploadValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了System.Net.WebClient.UploadValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/png";
string prefFilter = context.Request["pref"] ?? "全て";
string cityFilter = context.Request["city"] ?? "全て";
string categoryFilter = context.Request["category"] ?? "全て";
string productFilter = context.Request["product"] ?? "全て";
string publishDayFilter = context.Request["publish"] ?? "全て";
string pickDayFilter = context.Request["pick"] ?? "全て";
string sortItem = context.Request["sort"] ?? "1";
string widthString = context.Request["width"] ?? "";
string heightString = context.Request["height"] ?? "";
int width, height;
if (Int32.TryParse(widthString, out width) == false) width = 600;
if (Int32.TryParse(heightString, out height) == false) height = 300;
width = Math.Min(1000, Math.Max(300, width));
height = Math.Min(600, Math.Max(150, height));
var list = Common.GetQuery(prefFilter, cityFilter, categoryFilter, productFilter, publishDayFilter, pickDayFilter, sortItem);
var param = list.Item1.ToList().PrepareChartParam(width, height);
using (var cl = new System.Net.WebClient())
{
var values = new System.Collections.Specialized.NameValueCollection();
foreach (var item in param)
{
values.Add(item.Substring(0, item.IndexOf('=')), item.Substring(item.IndexOf('=') + 1));
}
var resdata = cl.UploadValues("http://chart.googleapis.com/chart?chid=1", values);
context.Response.OutputStream.Write(resdata, 0, resdata.Length);
}
}
示例2: MoveToEnd
public void MoveToEnd()
{
var myNameValueCollection = new NameValueCollection();
myNameValueCollection.Add("value", "bottom");
System.Net.WebClient wc = new System.Net.WebClient();
wc.UploadValues(string.Format("https://api.trello.com/1/cards/{0}/pos/?key=84e85e930ddf12e10e2bf2f8fdcd0e7c&token=db720979dc6c046db2ce014a325bb6ad1a20bb4b3db8eac6c9859e94f7448082", this.Id), "Put", myNameValueCollection);
}
示例3: Api
public static string Api(string Temperature,string Humidity)
{
string url = (string)Properties.Settings.Default["ApiAddress"];
string resText = "";
try {
System.Net.WebClient wc = new System.Net.WebClient();
System.Collections.Specialized.NameValueCollection ps =
new System.Collections.Specialized.NameValueCollection();
ps.Add("MachineName", (string)Properties.Settings.Default["MachineName"]);
ps.Add("Temperature", Temperature);
ps.Add("Humidity", Humidity);
byte[] ResData = wc.UploadValues(url, ps);
wc.Dispose();
resText = System.Text.Encoding.UTF8.GetString(ResData);
if (resText != "OK")
{
return "APIエラー";
}
}
catch (Exception ex){
return ex.ToString();
}
return null;
}
示例4: PushUSBDevices
public static void PushUSBDevices(string[] args)
{
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBControllerDevice"))
collection = searcher.Get();
foreach (var device in collection) {
string strDeviceName = device["Dependent"].ToString();
string strQuotes = "'";
strDeviceName = strDeviceName.Replace("\"", strQuotes);
string[] arrDeviceName = strDeviceName.Split('=');
strDeviceName = arrDeviceName[1];
string Win32_PnPEntity = "Select * From Win32_PnPEntity "
+ "Where DeviceID =" + strDeviceName;
ManagementObjectSearcher mySearcher = new ManagementObjectSearcher(Win32_PnPEntity);
foreach (ManagementObject mobj in mySearcher.Get()) {
string strDeviceID = mobj["DeviceID"].ToString();
string[] arrDeviceID = strDeviceID.Split('\\');
Console.WriteLine("Device Description = " + mobj["Description"].ToString());
if (mobj["Manufacturer"] != null) {
Console.WriteLine("Device Manufacturer = "
+ mobj["Manufacturer"].ToString());
}
Console.WriteLine("Device Version ID & Vendor ID = " + arrDeviceID[1]);
Console.WriteLine("Device Name = " + mobj["Name"].ToString());
Console.WriteLine("System = " + mobj["SystemName"].ToString());
Console.WriteLine("PNP id = " + mobj["PNPDeviceID"].ToString());
var devId = arrDeviceID[2].Trim('{', '}');
var splitId = devId.Split('&');
if (splitId.Length > 1) {
devId = splitId[1];
}
Console.WriteLine("Device ID = " + devId);
try {
using (var client = new System.Net.WebClient()) {
var data = new NameValueCollection();
data["device"] = mobj["Name"].ToString();
data["system"] = mobj["SystemName"].ToString();
data["id"] = devId;
Console.WriteLine(args);
var response = client.UploadValues(args[0] + "/setDevice/", "POST", data);
}
}
catch (Exception) {
Console.WriteLine("unknown device");
}
Console.WriteLine("\n");
}
}
collection.Dispose();
}
示例5: ChangePasswordClick
protected void ChangePasswordClick(object sender, System.EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
var u = User.GetUser(0);
var user = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].GetUser(0, true);
user.ChangePassword(u.GetPassword(), tb_password.Text.Trim());
// Is it using the default membership provider
if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is UsersMembershipProvider)
{
// Save user in membership provider
var umbracoUser = user as UsersMembershipUser;
umbracoUser.FullName = tb_name.Text.Trim();
Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].UpdateUser(umbracoUser);
// Save user details
u.Email = tb_email.Text.Trim();
}
else
{
u.Name = tb_name.Text.Trim();
if (!(Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is ActiveDirectoryMembershipProvider)) Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].UpdateUser(user);
}
// we need to update the login name here as it's set to the old name when saving the user via the membership provider!
u.LoginName = tb_login.Text;
u.Save();
if (cb_newsletter.Checked)
{
try
{
var client = new System.Net.WebClient();
var values = new NameValueCollection {{"name", tb_name.Text}, {"email", tb_email.Text}};
client.UploadValues("http://umbraco.org/base/Ecom/SubmitEmail/installer.aspx", values);
}
catch { /* fail in silence */ }
}
if (String.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus))
UmbracoContext.Current.Security.PerformLogin(u.Id);
InstallHelper.RedirectToNextStep(Page, GetCurrentStep());
}
}
示例6: ChangeList
public void ChangeList(string newListId)
{
if (this.idList != newListId)
{
var myNameValueCollection = new NameValueCollection();
myNameValueCollection.Add("value", newListId);
System.Net.WebClient wc = new System.Net.WebClient();
wc.UploadValues(string.Format("https://api.trello.com/1/cards/{0}/idList/?key=84e85e930ddf12e10e2bf2f8fdcd0e7c&token=db720979dc6c046db2ce014a325bb6ad1a20bb4b3db8eac6c9859e94f7448082", this.Id), "Put", myNameValueCollection);
this.idList = newListId;
string tmp = wc.DownloadString(string.Format("https://api.trello.com/1/lists/{0}/name/?key=84e85e930ddf12e10e2bf2f8fdcd0e7c&token=db720979dc6c046db2ce014a325bb6ad1a20bb4b3db8eac6c9859e94f7448082", this.idList));
this.List = Jil.JSON.DeserializeDynamic(tmp)._value;
}
}
示例7: SetDueDate
public void SetDueDate(DateTime? dueDate)
{
if (this.DueDate != dueDate)
{
var myNameValueCollection = new NameValueCollection();
if (dueDate.HasValue)
{
myNameValueCollection.Add("value", dueDate.Value.ToString("o"));
}
else
{
myNameValueCollection.Add("value", null);
}
System.Net.WebClient wc = new System.Net.WebClient();
wc.UploadValues(string.Format("https://api.trello.com/1/cards/{0}/due/?key=84e85e930ddf12e10e2bf2f8fdcd0e7c&token=db720979dc6c046db2ce014a325bb6ad1a20bb4b3db8eac6c9859e94f7448082", this.Id), "Put", myNameValueCollection);
}
}
示例8: Push
public void Push()
{
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBControllerDevice"))
collection = searcher.Get();
foreach (var device in collection) {
var strDeviceName = device["Dependent"].ToString();
const string strQuotes = "'";
strDeviceName = strDeviceName.Replace("\"", strQuotes);
var arrDeviceName = strDeviceName.Split('=');
strDeviceName = arrDeviceName[1];
var Win32_PnPEntity = "Select * From Win32_PnPEntity " + "Where DeviceID =" + strDeviceName;
var mySearcher = new ManagementObjectSearcher(Win32_PnPEntity);
foreach (var mobj in mySearcher.Get()) {
var strDeviceID = mobj["DeviceID"].ToString();
var arrDeviceID = strDeviceID.Split('\\');
var devId = arrDeviceID[2].Trim('{', '}');
var splitId = devId.Split('&');
if (splitId.Length > 1) {
devId = splitId[1];
}
try {
using (var client = new System.Net.WebClient()) {
var data = new NameValueCollection();
data["device"] = mobj["Name"].ToString();
data["system"] = mobj["SystemName"].ToString();
data["id"] = devId;
if (!string.IsNullOrEmpty(_debugSystemName)) {
data["system"] = _debugSystemName;
}
client.UploadValues(_url + "/setDevice/", "POST", data);
}
}
catch (Exception) {
}
}
}
collection.Dispose();
}
示例9: getDNSINFO
public dynamic getDNSINFO()
{
string url = "https://www.cloudflare.com/api_json.html";
System.Net.WebClient wc = new System.Net.WebClient();
//NameValueCollectionの作成
System.Collections.Specialized.NameValueCollection ps = new System.Collections.Specialized.NameValueCollection();
//送信するデータ(フィールド名と値の組み合わせ)を追加
ps.Add("a", "rec_load_all");
ps.Add("tkn", KEY);
ps.Add("email", EMAIL);
ps.Add("z", DOMAIN);
//データを送信し、また受信する
byte[] resData = wc.UploadValues(url, ps);
wc.Dispose();
//受信したデータを表示する
string resText = System.Text.Encoding.UTF8.GetString(resData);
var model = new JavaScriptSerializer().Deserialize<dynamic>(resText);
for (int i = 0; i < model["response"]["recs"]["count"]; i++)
{
string type = model["response"]["recs"]["objs"][i]["type"];
if (type == "A")
{
return new
{
rec_id = model["response"]["recs"]["objs"][i]["rec_id"],
content = model["response"]["recs"]["objs"][i]["content"],
name = model["response"]["recs"]["objs"][i]["name"],
service_mode = model["response"]["recs"]["objs"][i]["service_mode"],
ttl = model["response"]["recs"]["objs"][i]["ttl"]
};
}
}
return null;
}
示例10: ProcessRequest
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/png";
var categoryName = context.Request["category"];
var productName = context.Request["product"];
using (var db = new DataClasses1DataContext())
{
IList<YasaiKensa> list;
if (categoryName == "野菜類")
{
var q = from x in db.YasaiKensa
where x.食品カテゴリ == categoryName && x.野菜品名 == productName
orderby x.採取日D descending
select x;
list = q.ToList();
}
else
{
var q = from x in db.YasaiKensa
where x.食品カテゴリ == categoryName && x.品目 == productName
orderby x.採取日D descending
select x;
list = q.ToList();
}
var param = list.ToList().PrepareChartParam(600, 300);
using (var cl = new System.Net.WebClient())
{
var values = new System.Collections.Specialized.NameValueCollection();
foreach (var item in param)
{
values.Add(item.Substring(0, item.IndexOf('=')), item.Substring(item.IndexOf('=') + 1));
}
var resdata = cl.UploadValues("http://chart.googleapis.com/chart?chid=1", values);
context.Response.OutputStream.Write(resdata, 0, resdata.Length);
}
}
}
示例11: ChangePasswordClick
protected void ChangePasswordClick(object sender, System.EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
var u = User.GetUser(0);
var user = CurrentProvider.GetUser(0, true);
if (user == null)
{
throw new InvalidOperationException("No user found in membership provider with id of 0");
}
//NOTE: This will throw an exception if the membership provider
try
{
var success = user.ChangePassword(u.GetPassword(), tb_password.Text.Trim());
if (!success)
{
PasswordValidator.IsValid = false;
PasswordValidator.ErrorMessage = "Password must be at least " + CurrentProvider.MinRequiredPasswordLength + " characters long and contain at least " + CurrentProvider.MinRequiredNonAlphanumericCharacters + " symbols";
return;
}
}
catch (Exception ex)
{
PasswordValidator.IsValid = false;
PasswordValidator.ErrorMessage = "Password must be at least " + CurrentProvider.MinRequiredPasswordLength + " characters long and contain at least " + CurrentProvider.MinRequiredNonAlphanumericCharacters + " symbols";
return;
}
// Is it using the default membership provider
if (CurrentProvider is UsersMembershipProvider)
{
// Save user in membership provider
var umbracoUser = user as UsersMembershipUser;
umbracoUser.FullName = tb_name.Text.Trim();
CurrentProvider.UpdateUser(umbracoUser);
// Save user details
u.Email = tb_email.Text.Trim();
}
else
{
u.Name = tb_name.Text.Trim();
if ((CurrentProvider is ActiveDirectoryMembershipProvider) == false)
{
CurrentProvider.UpdateUser(user);
}
}
// we need to update the login name here as it's set to the old name when saving the user via the membership provider!
u.LoginName = tb_login.Text;
u.Save();
if (cb_newsletter.Checked)
{
try
{
var client = new System.Net.WebClient();
var values = new NameValueCollection {{"name", tb_name.Text}, {"email", tb_email.Text}};
client.UploadValues("http://umbraco.org/base/Ecom/SubmitEmail/installer.aspx", values);
}
catch { /* fail in silence */ }
}
if (String.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus))
UmbracoContext.Current.Security.PerformLogin(u.Id);
InstallHelper.RedirectToNextStep(Page, GetCurrentStep());
}
}
示例12: apiCall
/**
* apiCall
* Make an API call to server based on action and parameters.
*
* @param string action API action name
* @param Dictionary xmlData Dictionary of xml data
* @return string xml response string from server.
*/
private string apiCall(string action, Dictionary<int, Dictionary<string, string>> xmlData)
{
if (action != "get-queue")
{
if (String.IsNullOrEmpty(this.targetType))
{
throw new Exception("Target type is null");
}
this.getServer(this.targetTypeOptions[this.targetType]);
}
using (var wb = new System.Net.WebClient())
{
var data = new System.Collections.Specialized.NameValueCollection();
data["queue"] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><queue>" + this.getDic2Xml(xmlData) + "</queue>";
var response = wb.UploadValues(OnlineConvert.URL + "/" + action, "POST", data);
string result = System.Text.Encoding.UTF8.GetString(response);
return result;
}
}
示例13: backgroundWorker_traffic_DoWork
private void backgroundWorker_traffic_DoWork(object sender, DoWorkEventArgs e)
{
ThreadInfo ti = (ThreadInfo)e.Argument;
if (null != ti)
{
BackgroundWorker worker = sender as BackgroundWorker;
worker.ReportProgress(0);
System.Net.WebClient webClient = new System.Net.WebClient();
System.Collections.Specialized.NameValueCollection coll = new System.Collections.Specialized.NameValueCollection();
String sUrl = "";
String sMethod = ti.method;
// build uri
String sProtocol = (checkBox_SSL.Checked) ? "https" : "http";
sUrl = sProtocol + "://" + ti.vs_def.address + ":" + ti.vs_def.port.ToString() + ti.uri;
if (sMethod.Equals("GET"))
{
}
// add headers
for (int i = 0; i < ti.header_names.Length; i++)
{
webClient.Headers.Add(ti.header_names[i], ti.header_values[i]);
}
// Loop through the listview items
for (int i = 0; i < ti.param_names.Length; i++)
{
if (sMethod.Equals("POST"))
{
// add the name value pairs to the value collection
coll.Add(ti.param_names[i], ti.param_values[i]);
}
else
{
// for GET's let's build the parameter list onto the URL.
if (0 == i)
{
sUrl = sUrl + "?";
}
else
{
sUrl = sUrl + "&";
}
sUrl = sUrl + ti.param_names[i] + "=" + ti.param_values[i];
}
}
worker.ReportProgress(25);
System.Net.NetworkCredential creds = new System.Net.NetworkCredential(ti.username, ti.password);
webClient.Credentials = creds;
if (null != ti.proxy)
{
webClient.Proxy = ti.proxy;
}
try
{
worker.ReportProgress(50);
byte[] responseArray = null;
if (sMethod.Equals("POST"))
{
responseArray = webClient.UploadValues(sUrl, sMethod, coll);
}
else
{
responseArray = webClient.DownloadData(sUrl);
}
worker.ReportProgress(75);
String sResponse = "";
if (null != responseArray)
{
for (int i = 0; i < responseArray.Length; i++)
{
sResponse += (char)responseArray[i];
}
}
if (sResponse.Length > 0)
{
e.Result = "Request Succeeded\n" + sResponse;
}
}
catch (Exception ex)
{
e.Result = ex.Message.ToString();
}
webClient.Dispose();
worker.ReportProgress(100);
}
}
示例14: IsHolidayByDate
/// <summary>
/// 判断是不是节假日,节假日返回true
/// </summary>
/// <param name="date">日期格式:yyyy-MM-dd</param>
/// <returns></returns>
public static bool IsHolidayByDate(string date)
{
bool isHoliday = false;
System.Net.WebClient WebClientObj = new System.Net.WebClient();
System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
PostVars.Add("d", date.Replace("-", ""));//参数
try
{
byte[] byRemoteInfo = WebClientObj.UploadValues(@"http://www.easybots.cn/api/holiday.php", "POST", PostVars);//请求地址,传参方式,参数集合
string sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);//获取返回值
string result = JObject.Parse(sRemoteInfo)[date.Replace("-", "")].ToString();
if (result == "0")
{
isHoliday = false;
}
else if (result == "1" || result == "2")
{
isHoliday = true;
}
}
catch
{
isHoliday = isWeekend(DateTime.Parse(date));
}
return isHoliday;
}
示例15: Main
public static void Main(string[] args)
{
NameValueCollection myNameValueCollection = null;
byte[] response;
string tmp;
System.Net.WebClient wc = new System.Net.WebClient();
tmp = wc.DownloadString(string.Format("https://api.trello.com/1/boards/{0}/cards/?key={1}&token={2}", "1KkeULJJ", KEY, TOKEN));
Console.Write("Getting cards...");
var cards = Jil.JSON.Deserialize<List<Card>>(tmp, new Options(dateFormat: DateTimeFormat.ISO8601));
Console.WriteLine(cards.Count);
int cnt = 0;
Console.WriteLine("Getting card details...");
Parallel.ForEach(cards, card =>
{
System.Net.WebClient wcParallel = new System.Net.WebClient();
string tmpRes = wcParallel.DownloadString(string.Format("https://api.trello.com/1/lists/{0}/name/?key={1}&token={2}", card.idList, KEY, TOKEN));
card.List = Jil.JSON.DeserializeDynamic(tmpRes)._value;
foreach (string checkListId in card.IdChecklists)
{
tmpRes = wcParallel.DownloadString(string.Format("https://api.trello.com/1/checklists/{0}/?key={1}&token={2}", checkListId, KEY, TOKEN));
CheckList checkList = Jil.JSON.Deserialize<CheckList>(tmpRes, new Options(dateFormat: DateTimeFormat.ISO8601));
if (checkList.Name == "Team Tasks")
{
card.TeamTasks = checkList;
foreach (CheckItem checkItem in card.TeamTasks.CheckItems)
{
string cardId = checkItem.Name.Replace("https://trello.com/c/", "") + "/";
cardId = cardId.Substring(0, cardId.IndexOf("/"));
tmpRes = wcParallel.DownloadString(string.Format("https://api.trello.com/1/cards/{0}/?key={1}&token={2}", cardId, KEY, TOKEN));
checkItem.Card = Jil.JSON.Deserialize<Card>(tmpRes, new Options(dateFormat: DateTimeFormat.ISO8601));
tmpRes = wcParallel.DownloadString(string.Format("https://api.trello.com/1/lists/{0}/name/?key={1}&token={2}", checkItem.Card.idList, KEY, TOKEN));
checkItem.Card.List = Jil.JSON.DeserializeDynamic(tmpRes)._value;
}
}
}
Interlocked.Increment(ref cnt);
if (cnt % 5 == 0 && cnt != cards.Count)
{
Console.WriteLine(cnt + "/" + cards.Count);
}
}
);
/*
foreach (Card card in cards)
{
tmp = wc.DownloadString(string.Format("https://api.trello.com/1/lists/{0}/name/?key={1}&token={2}", card.idList, KEY, TOKEN));
card.List = Jil.JSON.DeserializeDynamic(tmp)._value;
foreach (string checkListId in card.IdChecklists)
{
tmp = wc.DownloadString(string.Format("https://api.trello.com/1/checklists/{0}/?key={1}&token={2}", checkListId, KEY, TOKEN));
CheckList checkList = Jil.JSON.Deserialize<CheckList>(tmp, new Options(dateFormat: DateTimeFormat.ISO8601));
if (checkList.Name == "Team Tasks")
{
card.TeamTasks = checkList;
foreach (CheckItem checkItem in card.TeamTasks.CheckItems)
{
string cardId = checkItem.Name.Replace("https://trello.com/c/", "") + "/";
cardId = cardId.Substring(0, cardId.IndexOf("/"));
tmp = wc.DownloadString(string.Format("https://api.trello.com/1/cards/{0}/?key={1}&token={2}", cardId, KEY, TOKEN));
checkItem.Card = Jil.JSON.Deserialize<Card>(tmp, new Options(dateFormat: DateTimeFormat.ISO8601));
tmp = wc.DownloadString(string.Format("https://api.trello.com/1/lists/{0}/name/?key={1}&token={2}", checkItem.Card.idList, KEY, TOKEN));
checkItem.Card.List = Jil.JSON.DeserializeDynamic(tmp)._value;
}
}
}
++cnt;
if (cnt % 5 == 0 && cnt != cards.Count)
{
Console.WriteLine(cnt + "/" + cards.Count);
}
}
*/
Console.WriteLine(cards.Count + "/" + cards.Count);
foreach (Card card in cards)
{
if (card.TeamTasks != null && card.TeamTasks.Position != 1)
{
Console.Write("Do you want to move checkList {0} to top? ", card.TeamTasks.Name);
string answer = Console.ReadLine();
if (answer.Equals("y", StringComparison.InvariantCultureIgnoreCase))
{
myNameValueCollection = new NameValueCollection();
myNameValueCollection.Add("value", "1");
wc.UploadValues(string.Format("https://api.trello.com/1/checklists/{0}/pos?key={1}&token={2}", card.TeamTasks.Id, KEY, TOKEN), "Put", myNameValueCollection);
Console.WriteLine("Moved!");
//.........这里部分代码省略.........