当前位置: 首页>>代码示例>>C#>>正文


C# System.Net.WebClient.UploadString方法代码示例

本文整理汇总了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;
        }
开发者ID:Makk24,项目名称:GetHtmlPage,代码行数:25,代码来源:WebForm3.aspx.cs

示例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());
     }
 }
开发者ID:johncoffee,项目名称:eventblock,代码行数:27,代码来源:CoinbaseProvider.cs

示例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");
            }
        }
开发者ID:ccccccmd,项目名称:Orchard.WeChat,代码行数:60,代码来源:WeiXinDispatchActivity.cs

示例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);
            }
        }
开发者ID:kiichi54321,项目名称:Rawler,代码行数:47,代码来源:Keyphrase.cs

示例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 "";
         }
     }
 }
开发者ID:neovasolutions,项目名称:MSTeam_SmartParkingSystem_Phase3,代码行数:23,代码来源:LoginController.cs

示例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, "");
 }
开发者ID:Wangxx-Git,项目名称:JLib,代码行数:11,代码来源:LBS.cs

示例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;
 }
开发者ID:byronv5,项目名称:CKMobile,代码行数:14,代码来源:TenpayUtil.cs

示例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;
            }
        }
开发者ID:ContrailSky,项目名称:monaCsharp,代码行数:38,代码来源:methods.cs

示例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;
        }
开发者ID:conceptdev,项目名称:Facebook,代码行数:14,代码来源:Main.cs

示例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;
 }
开发者ID:TerraPass,项目名称:ATM,代码行数:21,代码来源:Bank.cs

示例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;
 }
开发者ID:Bobom,项目名称:kuanmai,代码行数:10,代码来源:HttpSercice.cs


注:本文中的System.Net.WebClient.UploadString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。