本文整理汇总了C#中System.Net.WebClient.UploadStringAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.UploadStringAsync方法的具体用法?C# WebClient.UploadStringAsync怎么用?C# WebClient.UploadStringAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.UploadStringAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DELETE
public static string DELETE(string uri, IDictionary<string, string> args)
{
try {
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
client.Headers["Connection"] = "Keep-Alive";
StringBuilder formattedParams = new StringBuilder();
IDictionary<string, string> parameters = new Dictionary<string, string>();
foreach (var arg in args)
{
parameters.Add(arg.Key, arg.Value);
formattedParams.AppendFormat("{0}={{{1}}}", arg.Key, arg.Key);
}
//Formatted URI
Uri baseUri = new Uri(uri);
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompletedDelete);
client.UploadStringAsync(baseUri, "DELETE", string.Empty);
allDone.Reset();
allDone.WaitOne();
return requestResult;
}
catch (WebException ex) {
return ReadResponse(ex.Response.GetResponseStream());
}
}
示例2: ChangePinWebService
/// <summary>
/// Change Pin webservice
/// </summary>
private void ChangePinWebService()
{
string apiUrl = RxConstants.changePin;
newPinHashed = Utilities.GetSHA256(objSettingsConfirmChangePinVM.Pin);
oldPinHashed = Utilities.GetSHA256(App.PIN);
try
{
ChangePinRequest objInputParam = new ChangePinRequest
{
mail = App.LoginEmailId,
pin = oldPinHashed,
newpin = newPinHashed,
system_version = "android",
app_version = "1.6",
branding_version = "MLP"
};
WebClient changepinswebservicecall = new WebClient();
var uri = new Uri(apiUrl, UriKind.RelativeOrAbsolute);
var json = JsonHelper.Serialize(objInputParam);
changepinswebservicecall.Headers["Content-type"] = "application/json";
changepinswebservicecall.UploadStringCompleted += ChangePinWebServiceCall_UploadStringCompleted;
changepinswebservicecall.UploadStringAsync(uri, "POST", json);
}
catch (Exception)
{
MessageBox.Show("Sorry, Unable to process your request.");
}
}
示例3: btn_Login
private void btn_Login(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtUserName.Text) || string.IsNullOrEmpty(txtPassword.Password ))
{
MessageBox.Show("Kullanıcı adı ve şifre alanları boş geçilemez.");
return;
}
Progress.IsIndeterminate = true;
txtUserName.IsEnabled = false;
txtPassword.IsEnabled = false;
LoginObject log = new LoginObject();
log.e = txtUserName.Text;
log.p = txtPassword.Password;
WebClient web = new WebClient();
web.Headers["Content-Type"] = "application/json";
web.Headers["User-Agent"] = "NeroIOS4/1.0.1 CFNetwork/609 Darwin/13.0.0";
web.UploadStringCompleted += web_UploadStringCompleted;
string PostData = JsonConvert.SerializeObject(log);
((ApplicationBarIconButton)sender).IsEnabled = false;
web.UploadStringAsync(new Uri("http://api.nero.mekanist.net/v2/user/login", UriKind.Absolute), "POST", PostData, sender);
}
示例4: Print
void Print(object sender, RoutedEventArgs e)
{
WebClientInfo wci = Application.Current.Resources["dbclient"] as WebClientInfo;
WebClient client = new WebClient();
client.UploadStringCompleted += wc_UploadStringCompleted;
client.UploadStringAsync(new Uri(wci.BaseAddress), String.Format("[{{\"operator\":\"sql\",\"data\":\"update t_fapiaoinfos set f_fapiaostatue='已用' where f_invoicenum={0}\"}}]", fapiaoNum1.Text));
}
示例5: btnLogin_Click
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (Validation() == true)
{
// show Loader
myIndeterminateProbar.Visibility = Visibility.Visible;
//====================================================================================================================
// Login Check
//====================================================================================================================
// Parameters
LoginRequest obj = new LoginRequest();
obj.email = txtUserName.Text.Trim(); // "djhs16";
obj.password = txtPassWord.Password.Trim(); //"qaz";
String data = "email=" + obj.email + "&password=" + obj.password;
//Initialize WebClient
WebClient webClient = new WebClient();
//Set Header
webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";
webClient.UploadStringAsync(new Uri(Utilities.GetURL("auth/signIn/")), "POST", data);
//Assign Event Handler
webClient.UploadStringCompleted += wc_UploadStringCompleted;
}
}
示例6: LoadUrl
private void LoadUrl(String us, String pwd)
{
StringBuilder parameter = new StringBuilder();
parameter.AppendFormat("{0}={1}&", "username", HttpUtility.UrlEncode(us));
parameter.AppendFormat("{0}={1}&", "password", HttpUtility.UrlEncode(pwd));
parameter.AppendFormat("{0}={1}&", "tag", HttpUtility.UrlEncode(us));
Navigation.Tag = parameter.AppendFormat("{0}={1}&", "tag", HttpUtility.UrlEncode(us)).ToString();
if (us.Equals("") || pwd.Equals(""))
{
Result = "Kosong";
MessageBox.Show("Username or Password should not be empty!");
}
else
{
try
{
WebClient clientLogin = new WebClient();
clientLogin.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
clientLogin.Headers[HttpRequestHeader.ContentLength] = parameter.Length.ToString();
clientLogin.UploadStringCompleted += new UploadStringCompletedEventHandler(uploadLoginComplete);
clientLogin.UploadStringAsync(new Uri(URL.BASE3 + "APIv2/landing/login.php"), "POST", parameter.ToString());
}
catch
{
Result = "false";
}
}
}
示例7: GetUserDetailsWebService
/// <summary>
/// To get the user details while login and display it when "continue" is clciked
/// </summary>
private void GetUserDetailsWebService()
{
string apiUrl = RxConstants.getUserDetails;
try
{
LoginParameters objLoginparameters = new LoginParameters
{
Mail = App.LoginEmailId,
Pharmacyid = App.LoginPharId.ToUpper(),
Pin = App.HashPIN,
system_version = "android",
app_version = "1.6",
branding_version = "MLP"
};
WebClient userdetailswebservicecall = new WebClient();
var uri = new Uri(apiUrl, UriKind.RelativeOrAbsolute);
var json = JsonHelper.Serialize(objLoginparameters);
userdetailswebservicecall.Headers["Content-type"] = "application/json";
userdetailswebservicecall.UploadStringCompleted += userdetailswebservicecall_UploadStringCompleted;
userdetailswebservicecall.UploadStringAsync(uri, "POST", json);
}
catch (Exception)
{
MessageBox.Show("Sorry, Unable to process your request.");
}
}
示例8: WatcherOnPositionChanged
private void WatcherOnPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (DateTime.Now.TimeOfDay.Subtract(_lastTimeSend) >= _minSendTime)
{
_geozoneRequest.Lat = e.Position.Location.Latitude;
_geozoneRequest.Lon = e.Position.Location.Longitude;
WebClient webClient = new WebClient();
webClient.UploadStringCompleted += (o, args) =>
{
if (args.Error == null)
{
JObject jRoot = JObject.Parse(args.Result);
if (JsonHelpers.GetStatusCode(jRoot) == 200)
{
double dist = jRoot["response"].Value<double>("distance");
if (dist > 0)
_watcher.MovementThreshold = dist/2;
}
}
};
string request = string.Format("{{\"request\":{0}}}", JsonConvert.SerializeObject(_geozoneRequest));
webClient.UploadStringAsync(Constants.GeozoneUrl, request);
_lastTimeSend = DateTime.Now.TimeOfDay;
}
}
示例9: ClientePost
public void ClientePost()
{
try
{
List<Cliente> listCliente = ClienteDB.GetAll();
for (int x = 0; listCliente.Count() > x; x++)
{
WebClient webClient = new WebClient();
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
webClient.Encoding = Encoding.UTF8;
webClient.UploadStringAsync(new Uri("http://apiatenda.azurewebsites.net/api/cliente/"), "POST",
"&Nome=" + listCliente[x].Nome +
"&Telefone=" + listCliente[x].Telefone +
"&Endereco=" + listCliente[x].Endereco +
"&Bairro=" + listCliente[x].Bairro +
"&Cidade=" + listCliente[x].Cidade +
"&Estado=" + listCliente[x].Estado +
"&CPF_CNPJ=" + listCliente[x].CPF_CNPJ);
}
}
catch (ArgumentNullException ex)
{
MessageBox.Show(ex.Message);
}
}
示例10: AgendaPost
public void AgendaPost()
{
try
{
List<Agenda> listAgenda = AgendaDB.GetAll();
for (int x = 0; listAgenda.Count() > x; x++)
{
WebClient webClient = new WebClient();
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
webClient.Encoding = Encoding.UTF8;
webClient.UploadStringAsync(new Uri("http://apiatenda.azurewebsites.net/api/agenda/"), "POST",
"&IdTecnico=" + listAgenda[x].IdTecnico +
"&IdCliente=" + listAgenda[x].IdCliente +
"&Hora=" + listAgenda[x].Hora +
"&Data=" + listAgenda[x].Data +
"&Local=" + listAgenda[x].Local +
"&Servicos=" + listAgenda[x].Servicos +
"&Observacoes=" + listAgenda[x].Observacoes +
"&Status=" + listAgenda[x].Status);
}
}
catch (ArgumentNullException ex)
{
MessageBox.Show(ex.Message);
}
}
示例11: SendKey
public void SendKey(String key, String data)
{
WebClient client = new WebClient();
// XBMC媒体中心服务器
String JSON_RPC = "http://" + userSettings["host"] + "/jsonrpc?SendRemoteKey";
// WebClient 加载完成后的事件
// application/json; charset=UTF-8
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
switch (key)
{
case "VolumeUp":
client.UploadStringCompleted += new UploadStringCompletedEventHandler(user_VolumeUpCallback);
break;
case "VolumeDown":
client.UploadStringCompleted += new UploadStringCompletedEventHandler(user_VolumeDownCallback);
break;
default:
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
break;
}
try
{
// String data = "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Up\", \"id\": 1}";
client.Headers[HttpRequestHeader.ContentLength] = data.Length.ToString();
client.UploadStringAsync(new Uri(JSON_RPC), "POST", data);
}
catch { }
}
示例12: BatchAction
/// <summary>
/// 批量
/// </summary>
/// <param name="cmd"></param>
private void BatchAction(String cmd)
{
WebClient wc = new WebClient();
Indicator.IsBusy = true;
wc.UploadStringCompleted += wc_UploadStringCompleted;
wc.UploadStringAsync(new Uri(list.WebClientInfo.BaseAddress), cmd);
}
示例13: hueconfigure
/// <summary>
/// Prepares a hue bridge to allow the application to interact with it - needs to be run once per bridge.
/// </summary>
/// <param name="bridgeip">IP address of the bidge to connect to.</param>
/// <param name="uname">Username for the paplication to use.</param>
/// <returns>Boolean value depending on whether registration was a success.</returns>
public bool hueconfigure(string bridgeip, string uname)
{
var client = new WebClient();
Tools.Log log = new Tools.Log();
//our uri to perform registration
var uri = new Uri(string.Format("http://{0}/api", bridgeip));
//create our registration object, along with username and description
var reg = new
{
username = uname,
devicetype = Properties.Resources.APPLICATION_TITLE
};
var jsonObj = JsonConvert.SerializeObject(reg);
//decide what to do with the response we get back from the bridge
client.UploadStringCompleted += (o, args) =>
{
try
{
log.Write(Properties.Resources.LOG_HUE_BRIDGE_RESPONSE + " " + args.Result);
}
catch (Exception ex)
{
log.Write(Properties.Resources.LOG_HUE_BRIDGE_EXCEPTION + " " + ex.Message);
}
};
//Invoke a POST to the bridge
client.UploadStringAsync(uri, jsonObj);
//WriteLog("Connection request sent (hope you pressed the button!");
return true;
}
示例14: MakeRequest
public void MakeRequest(string type, string platform, string reqjsondata)
{
System.Text.UTF8Encoding en = new System.Text.UTF8Encoding();
string secret = Configs.Secret;
string uri = "http://api.bf3stats.com/" + platform + "/" + type + "/";
WebClient wc = new WebClient();
wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
if (type == "setupkey")
{
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(completed_register);
}
else
{
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(completed_update);
secret = Configs.GetAPIkey();
}
System.Security.Cryptography.HMACSHA256 hmac = new System.Security.Cryptography.HMACSHA256(en.GetBytes(secret));
Byte[] bytes = en.GetBytes(reqjsondata);
string encodedRequest = Convert.ToBase64String(bytes).Replace('+', '-').Replace('/', '_').Replace("=", "");
byte[] hashVal = hmac.ComputeHash(en.GetBytes(encodedRequest));
string signature = Convert.ToBase64String(hashVal).Replace('+', '-').Replace('/', '_').Replace("=", "");
string query = "data=" + encodedRequest + "&sig=" + signature;
wc.UploadStringAsync(new Uri(uri), "POST", query);
}
示例15: ResendBySmsWebService
/// <summary>
/// VerifyBySmsWebService Method
/// </summary>
private void ResendBySmsWebService()
{
string apiUrl = RxConstants.resendConfirmationCodes;
try
{
ResendConfirmationCodesRequest objInputParam = new ResendConfirmationCodesRequest
{
mail = App.YourDetailsLoginEmail,
pin = App.HashPIN,
pharmacyid = App.SignUpPharId.ToUpper(),
system_version = "android",
app_version = "1.6",
branding_version = "MLP"
};
WebClient resetpinswebservicecall = new WebClient();
var uri = new Uri(apiUrl, UriKind.RelativeOrAbsolute);
var json = JsonHelper.Serialize(objInputParam);
resetpinswebservicecall.Headers["Content-type"] = "application/json";
resetpinswebservicecall.UploadStringCompleted += resetpinswebservicecall_UploadStringCompleted;
resetpinswebservicecall.UploadStringAsync(uri, "POST", json);
}
catch (Exception)
{
MessageBox.Show("Sorry, Unable to process your request.");
}
}