本文整理汇总了C#中System.Net.WebClient.UploadValues方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.UploadValues方法的具体用法?C# WebClient.UploadValues怎么用?C# WebClient.UploadValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.UploadValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSwtTokenFromAcs
private static string GetSwtTokenFromAcs(string serviceNamespace, string clientId, string clientSecret, string scope)
{
WebClient client = new WebClient();
client.BaseAddress = string.Format(CultureInfo.CurrentCulture,
"https://{0}.{1}",
serviceNamespace,
"accesscontrol.windows.net");
NameValueCollection values = new NameValueCollection();
values.Add("grant_type", "client_credentials");
values.Add("client_id", clientId);
values.Add("client_secret", clientSecret);
values.Add("scope", scope);
byte[] responseBytes = null;
try
{
responseBytes = client.UploadValues("/v2/OAuth2-13", "POST", values);
}
catch (WebException ex)
{
throw new InvalidOperationException(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
}
string response = Encoding.UTF8.GetString(responseBytes);
// Parse the JSON response and return the access token
var serializer = new JavaScriptSerializer();
Dictionary<string, object> decodedDictionary = serializer.DeserializeObject(response) as Dictionary<string, object>;
return decodedDictionary["access_token"] as string;
}
示例2: Pull
public static string[] Pull(string url, NameValueCollection postfields)
{
WebClient webclient = new WebClient();
byte[] responsebytes = webclient.UploadValues("http://"+url, "POST", postfields);
string responsefromserver = Encoding.UTF8.GetString(responsebytes);
return SplitString(responsefromserver);
}
示例3: SendMessage
public string SendMessage(ISMSMessage m)
{
var message = (SMSMessage)m;
var builder = new StringBuilder();
string[] strArray = WebConfigurationManager.AppSettings.GetValues("SILVERSTREET_SMSServiceURL");
if (strArray != null)
{
builder.Append(strArray[0]);
}
var data = new NameValueCollection();
string[] values = WebConfigurationManager.AppSettings.GetValues("SILVERSTREET_SMSServiceUsername");
if (values != null)
{
data.Add("username", values[0]);
}
string[] strArray3 = WebConfigurationManager.AppSettings.GetValues("SILVERSTREET_SMSServicePassword");
if (strArray3 != null)
{
data.Add("password", strArray3[0]);
}
data.Add("destination", _formatter.FormatPhoneNumber(message.Recipient));
string[] strArray4 = WebConfigurationManager.AppSettings.GetValues("SILVERSTREET_SMSDefaultSender");
if (strArray4 != null)
{
data.Add("sender", strArray4[0]);
}
data.Add("body", message.Body);
using (var client = new WebClient())
{
byte[] bytes = client.UploadValues(new Uri(builder.ToString()), "POST", data);
return new UTF8Encoding().GetString(bytes);
}
}
示例4: RequestToken
public OAuthResponse RequestToken(string code)
{
NameValueCollection parameters = new NameValueCollection
{
{ "client_id", this.config.ClientId },
{ "client_secret", this.config.ClientSecret },
{ "grant_type", "authorization_code" },
{
"redirect_uri",
this.config.RedirectUri
},
{ "code", code }
};
var client = new WebClient();
var result = client.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters);
var response = System.Text.Encoding.Default.GetString(result);
var responseObject = (JObject)JsonConvert.DeserializeObject(response);
return new OAuthResponse()
{
AccessToken = (string)responseObject["access_token"],
User = new UserInfo()
{
Id = Convert.ToInt64(responseObject["user"]["id"]),
Username = responseObject["user"]["username"].ToString(),
FullName = responseObject["user"]["full_name"].ToString(),
ProfilePicture = responseObject["user"]["profile_picture"].ToString()
}
};
}
示例5: DoAuth
/// <summary>
/// Starts the auth process and
/// </summary>
/// <returns>A new Token</returns>
public Token DoAuth()
{
using (WebClient wc = new WebClient())
{
wc.Proxy = null;
wc.Headers.Add("Authorization",
"Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(ClientId + ":" + ClientSecret)));
NameValueCollection col = new NameValueCollection
{
{"grant_type", "client_credentials"},
{"scope", Scope.GetStringAttribute(" ")}
};
byte[] data;
try
{
data = wc.UploadValues("https://accounts.spotify.com/api/token", "POST", col);
}
catch (WebException e)
{
using (StreamReader reader = new StreamReader(e.Response.GetResponseStream()))
{
data = Encoding.UTF8.GetBytes(reader.ReadToEnd());
}
}
return JsonConvert.DeserializeObject<Token>(Encoding.UTF8.GetString(data));
}
}
示例6: SendCommand
public static string SendCommand(string cmd, string param, MessageType type)
{
string response = "";
using (var wb = new WebClient())
{
NetworkCredential cred = new NetworkCredential(Config.WebIOPiUser, Config.WebIOPiPassword);
wb.Credentials = cred;
Console.WriteLine("Sending command to Pi " + Config.WebIOPiURI + cmd);
if (type == MessageType.GET)
{
response = wb.DownloadString(Config.WebIOPiURI + cmd);
}
else if(type == MessageType.POST)
{
var data = new NameValueCollection();
data["username"] = "webiopi";
data["password"] = "raspberry";
var result = wb.UploadValues(Config.WebIOPiURI + cmd, data);
response = Encoding.Default.GetString(result);
}
}
Console.WriteLine("Received response from Pi : " + response);
return response;
}
示例7: postItemType
internal static void postItemType(modelPOS mPOS)
{
string result = "";
try
{
if (mPOS.reason.Length > 2)
{
using (WebClient client = new WebClient { UseDefaultCredentials = true })
{
byte[] response = client.UploadValues("http://api.olpl.org/api/positemcreate", new NameValueCollection()
{
{ "transID", mPOS.transID.ToString() },
{ "itemType", mPOS.reason },
{ "itemQuantity", mPOS.quantity.ToString() },
{ "itemPrice", mPOS.amtCol.ToString() },
{ "itemID", mPOS.itemID },
{ "totalPrice", mPOS.totalBill.ToString() },
{ "itemTitle", mPOS.title },
{ "itemAuthor", mPOS.author },
{ "itemCallNumber", mPOS.callnumber },
{ "transType", mPOS.transType },
{ "stationType", mPOS.stationType }
});
result = System.Text.Encoding.UTF8.GetString(response);
}
}
}
catch (Exception e1) { }
//return int.Parse(result);
}
示例8: GetTokenFromACS
private static string GetTokenFromACS(string scope)
{
string wrapPassword = pwd;
string wrapUsername = uid;
// request a token from ACS
WebClient client = new WebClient();
client.BaseAddress = string.Format("https://{0}.{1}", serviceNamespace, acsHostUrl);
NameValueCollection values = new NameValueCollection();
values.Add("wrap_name", wrapUsername);
values.Add("wrap_password", wrapPassword);
values.Add("wrap_scope", scope);
byte[] responseBytes = client.UploadValues("WRAPv0.9/", "POST", values);
string response = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine("\nreceived token from ACS: {0}\n", response);
return HttpUtility.UrlDecode(
response
.Split('&')
.Single(value => value.StartsWith("wrap_access_token=", StringComparison.OrdinalIgnoreCase))
.Split('=')[1]);
}
示例9: UploadCrashLog
private static void UploadCrashLog()
{
string crashLog = FullPath;
if (File.Exists(crashLog)) {
Task.Factory.StartNew(() => {
try {
string crashText = File.ReadAllText(crashLog);
//uncomment if we want to rename the crash log after uploading it
//string oldPath = Path.ChangeExtension(crashLog, ".old");
//if (File.Exists(oldPath))
// File.Delete(oldPath);
//File.Move(crashLog, oldPath);
using (var wb = new WebClient()) {
var data = new NameValueCollection();
data["id"] = disParity.Version.GetID().ToString();
data["crash"] = crashText;
Uri uri = new Uri(@"http://www.vilett.com/disParity/crash.php");
byte[] response = wb.UploadValues(uri, "POST", data);
}
}
catch (Exception e) {
LogFile.Log("Error uploading crash log: " + e.Message);
}
});
}
}
示例10: GetData
public string GetData(string url, NameValueCollection values,out Exception ex)
{
using (WebClient w = new WebClient())
{
w.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
//System.Collections.Specialized.NameValueCollection VarPar = new System.Collections.Specialized.NameValueCollection();
//VarPar.Add("userAccount", "drcl1858");
//VarPar.Add("pwd", "aHVpaGU4MDAz");
//VarPar.Add("valid", "FB68F3B5FC7CF00F5701CD796F1C8649");
string sRemoteInfo;
byte[] byRemoteInfo;
try
{
byRemoteInfo = w.UploadValues(url, "POST", values);
sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
}
catch(Exception e)
{
ex = e;
return string.Empty ;
}
ex = null;
return sRemoteInfo;
}
}
示例11: GetToken
public Token GetToken()
{
// web client
var client = new System.Net.WebClient();
// invoke the REST method
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string credentials = Convert.ToBase64String(
Encoding.ASCII.GetBytes(string.Format("{0}:{1}", _credentials.ClientId, _credentials.ClientSecret)));
client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
var postVaules = new NameValueCollection
{
{"username",_credentials.Username},
{"password", _credentials.Password},
{"grant_type", GrantTpype.Password}
};
try
{
byte[] result = client.UploadValues(TokenUrl, "POST", postVaules);
var jsonData = Encoding.UTF8.GetString(result);
var token = JsonConvert.DeserializeObject<Token>(jsonData);
return token;
}
catch (WebException ex)
{
if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadRequest)
{
throw new WebException("Failed to request access token. Check you OAuth credentials.");
}
}
return null;
}
示例12: LogInToPasteBin
string LogInToPasteBin()
{
if (_pastebinUserKey != null)
return _pastebinUserKey;
string userName = "SomeoneWeird";
string pwd = "";
NameValueCollection values = new NameValueCollection();
values.Add("api_dev_key", pastebin_dev_key);
values.Add("api_user_name", userName);
values.Add("api_user_password", pwd);
using (WebClient wc = new WebClient())
{
byte[] respBytes = wc.UploadValues(pastebin_login_url, values);
string resp = Encoding.UTF8.GetString(respBytes);
if (resp.Contains("Bad API request"))
{
Console.Write("Error:" + resp);
return null;
}
_pastebinUserKey = resp;
}
return _pastebinUserKey;
}
示例13: ApiGetBadIports
public string ApiGetBadIports()
{
TraceLogObj.WriteToLog(ThreadName, ObjectName, GetCurrentMethod(), "Start Call: ApiGetBadIports");
TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), ApiCompiledPath + "schedule.php ---- Get Bad Imports.");
string response;
//Console.WriteLine("Upload FIle: " + UploadFile);
using (WebClient client = new WebClient())
{
NameValueCollection parameters = InitParameters();
TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), parameters.Get("username"));
TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), parameters.Get("apikey"));
parameters.Add("func", "bad");
try
{
var responseBytes = client.UploadValues(ApiCompiledPath + "schedule.php", "POST", parameters);
response = Encoding.ASCII.GetString(responseBytes);
}
catch (Exception e)
{
response = "Error";
TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), e.Message);
}
}
TraceLogObj.WriteToLog(ThreadName, ObjectName, GetCurrentMethod(), "End Call: ApiGetBadIports");
return response;
}
示例14: RefreshGoogleAuthToken
/// <summary>
/// Explicitly refreshes the Google Auth Token. Usually not necessary.
/// </summary>
public void RefreshGoogleAuthToken()
{
string authUrl = "https://www.google.com/accounts/ClientLogin";
var data = new NameValueCollection();
data.Add("Email", this.androidSettings.SenderID);
data.Add("Passwd", this.androidSettings.Password);
data.Add("accountType", "GOOGLE_OR_HOSTED");
data.Add("service", "ac2dm");
data.Add("source", this.androidSettings.ApplicationID);
var wc = new WebClient();
try
{
var authStr = Encoding.ASCII.GetString(wc.UploadValues(authUrl, data));
//Only care about the Auth= part at the end
if (authStr.Contains("Auth="))
googleAuthToken = authStr.Substring(authStr.IndexOf("Auth=") + 5);
else
throw new GoogleLoginAuthorizationException("Missing Auth Token");
}
catch (WebException ex)
{
var result = "Unknown Error";
try { result = (new System.IO.StreamReader(ex.Response.GetResponseStream())).ReadToEnd(); }
catch { }
throw new GoogleLoginAuthorizationException(result);
}
}
示例15: IssueReport
public static void IssueReport(AhhhDragonsReport report)
{
if (!(report.Map == 38 || report.Map == 94 || report.Map == 95 || report.Map == 96))
return;
var serializer = new JavaScriptSerializer();
if (!string.IsNullOrWhiteSpace(report.Name))
{
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["mtc"] = report.MistsTrackingCode;
data["name"] = report.Name;
data["map"] = report.Map.ToString();
data["posx"] = report.PosX.ToString();
data["posy"] = report.PosY.ToString();
data["posz"] = report.PosZ.ToString();
data["friendly"] = report.GroupAllegiance == AhhhDragonsReport.PlayerGroupAllegiance.Friend ? "1" : "0";
data["size"] = ((int)report.GroupSize).ToString();
var response = wb.UploadValues("http://ahhhdragons.com/db/wvw.php", "POST", data);
System.Diagnostics.Debug.WriteLine(Encoding.ASCII.GetString(response));
}
}
}