本文整理汇总了C#中WebClient.UploadValues方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.UploadValues方法的具体用法?C# WebClient.UploadValues怎么用?C# WebClient.UploadValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebClient
的用法示例。
在下文中一共展示了WebClient.UploadValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
/// <summary>
/// Отправляет запрос серверу контекстной рекламы.
/// </summary>
/// <param name="uri">
/// Строка подключения к серверу конеткстной рекламы.
/// </param>
/// <param name="timeout">
/// Таймаут ожидания ответа от сервера контекстной рекламы, секунды.
/// </param>
/// <param name="request">
/// Запрос серверу контекстной рекламы.
/// </param>
/// <returns>
/// Ответ сервера контекстной рекламы.
/// </returns>
public IResponse Send(string uri, int timeout, IRequest request)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentNullException("uri");
}
if (request == null)
{
throw new ArgumentNullException("request");
}
try
{
using (var client = new WebClient(timeout))
{
client.Encoding = Encoding.UTF8;
var collection = new NameValueCollection();
collection.Add("Receipt", (string)(Request)request);
var response = Encoding.UTF8.GetString(client.UploadValues(uri, collection));
return (Response)response;
}
}
catch (System.Net.WebException ex)
{
LogException(ex);
return new Response
{
Lines = new List<ResponseLine>()
};
}
}
示例2: GetToken
private void GetToken(string code)
{
using (var wb = new WebClient())
{
var parameters = new NameValueCollection
{
{"client_id", "7be60d85e67648d490d3126f73c77434"},
{"client_secret", "fba7cd45089e4cf7922b086310d19913"},
{"grant_type", "authorization_code"},
{"redirect_uri", "http://localhost:4719/"},
{"code", code}
};
var response = wb.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters);
string json = Encoding.ASCII.GetString(response);
try
{
var OauthResponse = (InstagramOAuthResponse)JsonConvert.DeserializeObject(json, typeof(InstagramOAuthResponse));
}
catch (Exception ex)
{
//handle ex if needed.
}
}
}
示例3: fredTries
private void fredTries()
{
try
{
using (var client = new WebClient())
{
var values = new NameValueCollection(); //key and value mapping
values["user_name"] = "chupacabra";
values["user_email"] = @"[email protected]";
values["user_password_new"] = "omnomnom";
var response = client.UploadValues("http://tral-ee.lo5.org/requestHandler.php", values); //google responds with error here...expected....same thing in postman
var responseString = Encoding.Default.GetString(response);
Debug.Log(responseString);
}
}
catch (System.InvalidOperationException e)
{
if (e is WebException)
{
Debug.Log(e.Message);
//Debug.Log (e.StackTrace);
Debug.Log(e.GetBaseException());
}
}
}
示例4: Post
public static byte[] Post(string uri, NameValueCollection pairs)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
response = client.UploadValues(uri, pairs);
}
return response;
}
示例5: PostMessage
//Post a message using a Payload object
public void PostMessage(Payload payload)
{
string payloadJson = JsonConvert.SerializeObject(payload);
using (WebClient client = new WebClient())
{
NameValueCollection data = new NameValueCollection();
data["payload"] = payloadJson;
var response = client.UploadValues(_uri, "POST", data);
//The response text is usually "ok"
string responseText = _encoding.GetString(response);
}
}
示例6: VerifyEmail
public bool VerifyEmail(string emailVerify)
{
using (WebClient webclient = new WebClient())
{
string url = "http://verify-email.org/";
NameValueCollection formData = new NameValueCollection();
formData["check"] = emailVerify;
byte[] responseBytes = webclient.UploadValues(url, "POST", formData);
string response = Encoding.ASCII.GetString(responseBytes);
if (response.Contains("Result: Ok"))
{
return true;
}
return false;
}
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Request.RequestType != "GET") {
Fail("Request must be a GET");
return;
}
string temporaryCode = Request.Params["code"];
if (String.IsNullOrWhiteSpace(temporaryCode)) {
Fail("Argument required: code");
return;
}
try {
var serviceUri = "https://github.com/login/oauth/access_token";
var nvc = new NameValueCollection {
{"client_id", JSIL.Try.OAuth.ClientID},
{"client_secret", JSIL.Try.OAuth.Secret},
{"code", temporaryCode}
};
ServicePointManager.ServerCertificateValidationCallback = Validator;
using (var client = new WebClient()) {
var responseBytes = client.UploadValues(serviceUri, nvc);
var responseText = Encoding.ASCII.GetString(responseBytes);
var responseNvc = HttpUtility.ParseQueryString(responseText);
var responseDict = new Dictionary<string, object>();
foreach (var k in responseNvc.Keys)
responseDict[(string)k] = responseNvc[(string)k];
WriteResponseJSON(new {
ok = responseDict.ContainsKey("access_token"),
response = responseDict
});
}
} catch (Exception exc) {
Fail(exc);
}
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if(Request["code"]!=null)
{
string code = Request["code"];
NameValueCollection vc = new NameValueCollection();
vc.Add("client_id", "100124859d2b615ed99a");
vc.Add("client_secret", "71a60afcdee5ef6d11115983ec3f0bacc520562e");
vc.Add("code", code);
WebClient wc = new WebClient();
wc.Headers["Accept"] = "text/xml";
string response = UTF8Encoding.UTF8.GetString(wc.UploadValues("https://github.com/login/oauth/access_token", vc));
XDocument xd = XDocument.Parse(response);
string access_token = xd.Element("OAuth").Element("access_token").Value;
Response.Redirect("/?access_token=" + access_token);
}
}
示例9: SendMail
public int SendMail(string mail_sender, string mail_from, string mail_to, string mail_subject, string mail_body )
{
int r = 0;
WebClient webClient = new WebClient();
NameValueCollection postVal = new NameValueCollection();
postVal.Add("mail_sender", mail_sender);
postVal.Add("mail_from", mail_from);
postVal.Add("mail_to", mail_to);
postVal.Add("mail_subject", mail_subject);
postVal.Add("mail_body", mail_body);
try
{
byte[] result = webClient.UploadValues("http://localhost/mail/OmeiSendMail.asp", "POST", postVal);
string s = Encoding.ASCII.GetString(result);
r = int.Parse(s);
}
catch (WebException ex)
{
r = -1;
m_errorMessage = ex.ToString();
}
return r;
}
示例10: maxTries
private void maxTries()
{
try
{
using (var client = new WebClient())
{
var values = new NameValueCollection(); //key and value mapping
values["thing1"] = "hello";
values["thing2"] = "world";
var response = client.UploadValues("http://www.google.com", values); //google responds with error here...expected....same thing in postman
var responseString = Encoding.Default.GetString(response);
Debug.Log(responseString);
}
}
catch (System.InvalidOperationException e)
{
if (e is WebException)
{
Debug.Log(e.Message);
//Debug.Log (e.StackTrace);
Debug.Log(e.GetBaseException());
}
}
}
示例11: perform_request
public string perform_request(NameValueCollection RequestApi)
{
string Result = string.Empty;
using (WebClient client = new WebClient())
{
client.Headers.Add("KeepsAlive", "true");
Byte[] responseData = client.UploadValues("https://www.shiftplanning.com/api/", RequestApi);
Result = System.Text.Encoding.ASCII.GetString(responseData);
currentResponse = new DataSet();
currentResponse = XmlString2DataSet(Result);
}
return Result;
}
示例12: SendPaymentInfoAIM
public string SendPaymentInfoAIM(OrderDetailsCollection OrderDetail, string TemplateName, string addressPath)
{
WebClient objRequest = new WebClient();
System.Collections.Specialized.NameValueCollection objInf = new System.Collections.Specialized.NameValueCollection(30);
string strError;
//OrderDetail.ObjOrderDetails.CustomerID = int.Parse(Crypto.GenerateCustomerID());
OrderDetail.ObjOrderDetails.InvoiceNumber = Crypto.GenerateInvoiceNumber();
OrderDetail.ObjOrderDetails.PurchaseOrderNumber = Crypto.GeneratePurchaseOrderNumber();
//merchant generated field
objInf.Add("x_version", OrderDetail.ObjOrderDetails.Version);
objInf.Add("x_delim_data", OrderDetail.ObjOrderDetails.DelimData);
objInf.Add("x_login", OrderDetail.ObjOrderDetails.APILogin);
objInf.Add("x_tran_key", OrderDetail.ObjOrderDetails.TransactionKey);
objInf.Add("x_relay_response", OrderDetail.ObjOrderDetails.RelayResponse);
objInf.Add("x_delim_char", OrderDetail.ObjOrderDetails.DelimChar);
objInf.Add("x_encap_char", OrderDetail.ObjOrderDetails.EncapeChar);
objInf.Add("x_invoice_num", OrderDetail.ObjOrderDetails.InvoiceNumber);
objInf.Add("x_cust_id", OrderDetail.ObjOrderDetails.CustomerID.ToString());
objInf.Add("x_po_num", OrderDetail.ObjOrderDetails.PurchaseOrderNumber);
//for (int i = 0; i < arr; i++)
//{
//}
// Billing Address
objInf.Add("x_first_name", OrderDetail.ObjBillingAddressInfo.FirstName);
objInf.Add("x_last_name", OrderDetail.ObjBillingAddressInfo.LastName);
objInf.Add("x_company", OrderDetail.ObjBillingAddressInfo.CompanyName);
objInf.Add("x_email", OrderDetail.ObjBillingAddressInfo.EmailAddress);
objInf.Add("x_address", OrderDetail.ObjBillingAddressInfo.Address);
objInf.Add("x_city", OrderDetail.ObjBillingAddressInfo.City);
objInf.Add("x_state", OrderDetail.ObjBillingAddressInfo.State);
objInf.Add("x_zip", OrderDetail.ObjBillingAddressInfo.Zip);
objInf.Add("x_country", OrderDetail.ObjBillingAddressInfo.Country);
objInf.Add("x_phone", OrderDetail.ObjBillingAddressInfo.Phone);
objInf.Add("x_fax", OrderDetail.ObjBillingAddressInfo.Fax);
objInf.Add("x_email_customer", OrderDetail.ObjOrderDetails.IsEmailCustomer);
if (OrderDetail.ObjOrderDetails.IsMultipleCheckOut == false)
{
//shipping address
objInf.Add("x_ship_to_first_name", OrderDetail.ObjShippingAddressInfo.FirstName);
objInf.Add("x_ship_to_last_name", OrderDetail.ObjShippingAddressInfo.LastName);
objInf.Add("x_ship_to_company", OrderDetail.ObjShippingAddressInfo.CompanyName);
objInf.Add("x_ship_to_address", OrderDetail.ObjShippingAddressInfo.Address);
objInf.Add("x_ship_to_city", OrderDetail.ObjShippingAddressInfo.City);
objInf.Add("x_ship_to_state", OrderDetail.ObjShippingAddressInfo.State);
objInf.Add("x_ship_to_zip", OrderDetail.ObjShippingAddressInfo.Zip);
objInf.Add("x_ship_to_country", OrderDetail.ObjShippingAddressInfo.Country);
}
// Card Details
objInf.Add("x_card_num", OrderDetail.ObjPaymentInfo.CardNumber);
objInf.Add("x_card_type", OrderDetail.ObjPaymentInfo.CardType);
objInf.Add("x_exp_date", OrderDetail.ObjPaymentInfo.ExpireDate);
if (OrderDetail.ObjPaymentInfo.PaymentMethodCode=="CC")
{
// Authorization code of the card (CCV)
objInf.Add("x_card_code", OrderDetail.ObjPaymentInfo.CardCode.ToString());
objInf.Add("x_method", OrderDetail.ObjPaymentInfo.PaymentMethodCode);
objInf.Add("x_type", OrderDetail.ObjPaymentInfo.TransactionType);
string amount = Regex.Replace(OrderDetail.ObjOrderDetails.GrandTotal.ToString("0.00"), @"[A-Z]", String.Empty);
objInf.Add("x_amount", amount);
objInf.Add("x_description", OrderDetail.ObjOrderDetails.Remarks);
objInf.Add("x_test_request", OrderDetail.ObjOrderDetails.IsTest);
}
else
{
//bank
objInf.Add("x_bank_aba_code", OrderDetail.ObjPaymentInfo.RoutingNumber);
objInf.Add("x_bank_acct_num", OrderDetail.ObjPaymentInfo.AccountNumber);
objInf.Add("x_bank_acct_type", OrderDetail.ObjPaymentInfo.AccountType);
objInf.Add("x_bank_name", OrderDetail.ObjPaymentInfo.BankName);
objInf.Add("x_bank_acct_name", OrderDetail.ObjPaymentInfo.AccountHolderName);
objInf.Add("x_echeck_type", OrderDetail.ObjPaymentInfo.ChequeType);
objInf.Add("x_bank_check_number", OrderDetail.ObjPaymentInfo.ChequeNumber);
}
// Currency setting. Check the guide for other supported currencies
objInf.Add("x_currency_code", OrderDetail.ObjOrderDetails.CurrencyCode);
objRequest.BaseAddress ="https://test.authorize.net/gateway/transact.dll";
try
{
// POST request
byte[] objRetBytes;
string[] objRetVals;
objRetBytes =
objRequest.UploadValues(objRequest.BaseAddress, "POST", objInf);
objRetVals =
System.Text.Encoding.ASCII.GetString(objRetBytes).Split(",".ToCharArray());
// Process Return Values
OrderDetail.ObjOrderDetails.ResponseCode = int.Parse(objRetVals[0].Trim(char.Parse("|")));
OrderDetail.ObjOrderDetails.ResponseReasonCode = int.Parse(objRetVals[2].Trim(char.Parse("|")));
//.........这里部分代码省略.........
示例13: SendSMSV2ToUser
public static SMSStatus SendSMSV2ToUser(string numberTo, int orderID, int price)
{
using (WebClient client = new WebClient())
{
NameValueCollection values = new NameValueCollection();
Configuration config = SMSManager.SMSConfig;
string message = config.AppSettings.Settings["usertemplate"].Value.Replace("{orderNum}", orderID.ToString()).Replace("{price}", price.ToString());
values["XML"] = string.Format(XMLSendTemplate, config.AppSettings.Settings["login"].Value, config.AppSettings.Settings["password"].Value, config.AppSettings.Settings["sender"].Value, message, string.Format("<number>{0}</number>", numberTo));
byte[] response = client.UploadValues(XMLSendURL, values);
string responseString = Encoding.Default.GetString(response);
return GetStatus(responseString);
}
}
示例14: GetFromWebDB
int[] GetFromWebDB(string sql, string para)
{
int x = 0;
int y = 0;
try
{
using (var client = new WebClient())
{
var values = new NameValueCollection(); //key and value mapping
values ["act"] = "get";
values ["query"] = sql;
values ["para"] = para;
var response = client.UploadValues("http://tral-ee.lo5.org/statisticsHandler.php", values);
var responseString = Encoding.Default.GetString(response);
string[] responses = responseString.Split(' ');
Int32.TryParse(responses[0], out x);
Int32.TryParse(responses[1], out y);
int[] result = { x, y };
return result;
}
}
catch (System.InvalidOperationException e)
{
if (e is WebException)
{
Debug.Log(e.Message);
Debug.Log(e.GetBaseException());
}
}
int[] blah = { 0, 0 };
return blah;
}
示例15: ConcurrentOperations_Throw
public static async Task ConcurrentOperations_Throw()
{
await LoopbackServer.CreateServerAsync((server, url) =>
{
var wc = new WebClient();
Task ignored = wc.DownloadDataTaskAsync(url); // won't complete
Assert.Throws<NotSupportedException>(() => { wc.DownloadData(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadDataAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadDataTaskAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadString(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadStringAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadStringTaskAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadFile(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadFileAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadFileTaskAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadData(url, new byte[42]); });
Assert.Throws<NotSupportedException>(() => { wc.UploadDataAsync(url, new byte[42]); });
Assert.Throws<NotSupportedException>(() => { wc.UploadDataTaskAsync(url, new byte[42]); });
Assert.Throws<NotSupportedException>(() => { wc.UploadString(url, "42"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadStringAsync(url, "42"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadStringTaskAsync(url, "42"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadFile(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadFileAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadFileTaskAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadValues(url, new NameValueCollection()); });
Assert.Throws<NotSupportedException>(() => { wc.UploadValuesAsync(url, new NameValueCollection()); });
Assert.Throws<NotSupportedException>(() => { wc.UploadValuesTaskAsync(url, new NameValueCollection()); });
return Task.CompletedTask;
});
}