本文整理汇总了C#中System.Net.WebClient.UploadString方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.UploadString方法的具体用法?C# System.Net.WebClient.UploadString怎么用?C# System.Net.WebClient.UploadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了System.Net.WebClient.UploadString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHttpPage
public static string GetHttpPage(string url, string ntext, string post)
{
string ApiStatus = string.Empty;
using (System.Net.WebClient wc = new System.Net.WebClient())
{
wc.Encoding = System.Text.Encoding.UTF8;
try
{
if (!string.IsNullOrEmpty(post) && post.ToLower() == "post".ToLower())
{
ApiStatus = wc.UploadString(url, "POST", ntext);
}
else
{
ApiStatus = wc.DownloadString(url + "?" + ntext);
}
}
catch (Exception ex)
{
ApiStatus = "ERROR:" + ex.Message.ToString();
}
}
return ApiStatus;
}
示例2: using
void IPaymentProvider.RedirectToPaymentPage(ref string redirect)
{
string cbUrl = "https://api.coinbase.com/v2/checkouts";
JObject data = new JObject
{
{ "amount", "\"" + Order.Total.ToString() + "\"" },
{ "currency", "USD"},
{ "name", "Eventblock Order Ticket Online" },
{ "description", "" },
{ "type", "order" },
{ "style", "buy_now_large" },
{ "auto_redirect", true },
{ "success_url", "" },
{ "cancel_url", "" },
{ "metadata", new JObject {
{ "orderid", Order.OrdersId },
{ "rf", Order.ReferenceCode }
}
}
};
string result = "";
using (var client = new System.Net.WebClient())
{
client.Headers.Add("Content-Type", "application/json");
result = client.UploadString(cbUrl, "POST", data.ToString());
}
}
示例3: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
{
var part = workflowContext.Content.As<WXMsgPart>();
var apiUrl = activityContext.GetState<string>("api_url");
var apiToken = activityContext.GetState<string>("api_token");
var timestamp = HttpContext.Current.Request.QueryString["timestamp"];
var nonce = HttpContext.Current.Request.QueryString["nonce"];
string[] arr = { apiToken, timestamp, nonce };
Array.Sort(arr); //字典排序
string tmpStr = string.Join("", arr);
var signature = _winXinService.GetSHA1(tmpStr);
signature = signature.ToLower();
var client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.UTF8;
var url = string.Format("{0}?timestamp={1}&nonce={2}&signature={3}"
, apiUrl, timestamp, nonce, signature);
string postData = part.XML;
//using (var stream = HttpContext.Current.Request.InputStream)
//{
// var reader = new StreamReader(stream);
// postData = reader.ReadToEnd();
//}
string result = null;
try
{
result = client.UploadString(url, postData);
}
catch (System.Net.WebException ex)
{
string msg = null;
using (var stream = ex.Response.GetResponseStream())
{
var reader = new StreamReader(stream);
msg = reader.ReadToEnd();
}
Logger.Warning(ex, ex.Message);
}
catch (Exception ex)
{
var innerEx = ex;
while (innerEx.InnerException != null)
innerEx = innerEx.InnerException;
Logger.Warning(ex, innerEx.Message);
}
if (result == null)
{
yield return T("Error");
}
else
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(result);
HttpContext.Current.Response.End();
yield return T("Success");
}
}
示例4: Run
/// <summary>
/// このクラスでの実行すること。
/// </summary>
/// <param name="runChildren"></param>
public override void Run(bool runChildren)
{
string apiIds = ApiId;
if (string.IsNullOrEmpty(ApiId))
{
apiIds = Rawler.Tool.GlobalVar.GetVar("YahooApiId");
}
if (string.IsNullOrEmpty(apiIds))
{
Rawler.Tool.ReportManage.ErrReport(this, "YahooApiIdがありません。SetTmpValで指定してください");
return;
}
string apiId = apiIds.Split(',').OrderBy(n => Guid.NewGuid()).First();
string baseUrl = "http://jlp.yahooapis.jp/KeyphraseService/V1/extract";
var post = "appid=" + apiId + "&sentence=" +Uri.EscapeUriString(GetText());
string result = string.Empty;
try
{
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers.Add("Content-Type","application/x-www-form-urlencoded");
wc.Encoding = Encoding.UTF8;
result = wc.UploadString(new Uri(baseUrl), "POST", post);
wc.Dispose();
}
catch(Exception e)
{
ReportManage.ErrReport(this, e.Message +"\t"+GetText());
}
if (result != string.Empty)
{
var root = XElement.Parse(result);
var ns = root.GetDefaultNamespace();
var list = root.Descendants(ns + "Result").Select(n => new KeyphraseResult() { Keyphrase = n.Element(ns + "Keyphrase").Value, Score = double.Parse(n.Element(ns + "Score").Value) });
List<string> list2 = new List<string>();
foreach (var item in list)
{
list2.Add(Codeplex.Data.DynamicJson.Serialize(item));
}
base.RunChildrenForArray(runChildren, list2);
}
}
示例5: GetToken
private string GetToken(LoginModel model)
{
//string URI = "http://localhost:59822//oauth/token";
string URI = ConfigurationManager.AppSettings["as:TokenIssuer"].ToString();
string myParameters = "Username=" + model .UserName ;
myParameters += "&Password=" + model.Password ;
myParameters += "&grant_type=password";
myParameters += "&client_id=414e1927a3884f68abc79f7283837fd1";
using (System.Net.WebClient wc = new System.Net.WebClient())
{
wc.Headers[System.Net.HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
try
{
string HtmlResult = wc.UploadString(URI, myParameters);
Token token = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Token>(HtmlResult);
return token.access_token;
}
catch (Exception e)
{
return "";
}
}
}
示例6: GetJson
/// <summary>
/// 根据ip获取地址长串
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static string GetJson(string ip)
{
var url = "http://api.map.baidu.com/location/ip?ak=F454f8a5efe5e577997931cc01de3974&ip=" + ip + "&coor=bd09l";
var wc = new System.Net.WebClient {Encoding = Encoding.UTF8};
return wc.UploadString(url, "");
}
示例7: PostDataToUrl
/// <summary>
/// post数据到指定接口并返回数据
/// </summary>
public static string PostDataToUrl(string url, string postData)
{
string returnmsg;
using (System.Net.WebClient wc = new System.Net.WebClient())
{
LogHelper.WriteInfoLog("WebClient方式请求url:" + url + "。data:" + postData);
returnmsg = wc.UploadString(url, "POST", postData);
LogHelper.WriteInfoLog("WebClient方式请求返回:" + returnmsg);
}
return returnmsg;
}
示例8: RunCommand
//コマンド実行メソッド
//成功→受信json
//不成功→エラーメッセージ
public string RunCommand(string method, object[] param)
{
string url="", json="";
System.Web.Script.Serialization.JavaScriptSerializer jss
= new System.Web.Script.Serialization.JavaScriptSerializer();
url =
(mona_info[2].IndexOf("http") == -1)
?
"http://" + mona_info[2] + ":" + mona_info[3] + "/"
:
mona_info[2] + ":" + mona_info[3] + "/";
try
{
//Refer for Bitcoin-Tool
Dictionary<string, object> req = new Dictionary<string, object>();
req.Add("jsonrpc", "2.0");
req.Add("id", "1");
req.Add("method", method);
req.Add("params", param);
json = jss.Serialize(req);
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential(mona_info[0], mona_info[1]);
wc.Headers.Add("Content-type", "application/json-rpc");
json = wc.UploadString("http://" + mona_info[2] + ":" + mona_info[3], json);
return json;
}
catch (Exception ex)
{
return "[MESSAGE]" + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine
+"[SOURCE]" + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine
+ "[STACK_TRACE]" + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine
+ "[TARGET_SITE]" + Environment.NewLine + ex.TargetSite + Environment.NewLine;
}
}
示例9: UpdateStatus
/// <summary>
/// Update Facebook status
/// </summary>
public bool UpdateStatus(string status)
{
System.Net.WebClient wc = new System.Net.WebClient();
var result = wc.UploadString
("https://graph.facebook.com/me/feed?access_token=" + token
, "message=" + status);
// Expect the result to be a json string like this
// {"id":"689847836_129432987125279"}
return result.IndexOf ("id") > 0;
}
示例10: ConnectToDB
private string ConnectToDB(string url, string param)
{
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers.Set("Content-type", "application/x-www-form-urlencoded");
uint retries = 0;
string res = BANK_CONNECTION_ERROR;
while (retries < BANK_SERVER_CONNECTION_RETRIES)
{
try
{
res = wc.UploadString(BANK_SERVER_URL + url, "passkey=" + BANK_PASSKEY + '&' + param);
break;
}
catch (System.Net.WebException)
{
retries++;
continue;
}
}
return res;
}
示例11: PostXmlToUrl
public static string PostXmlToUrl(string url, NameValueCollection col, RequestType type)
{
string returnmsg = "";
string inputXML = getXMLInput(col, Encoding.UTF8);
using (System.Net.WebClient wc = new System.Net.WebClient())
{
returnmsg = wc.UploadString(url, type.ToString(), inputXML);
}
return returnmsg;
}