AW.Pay.Core.HTTPHelper.Post C# (CSharp) Method

Post() public static method

public static Post ( string url, string content, string contentType = "application/x-www-form-urlencoded" ) : string
url string
content string
contentType string
return string
        public static string Post(string url, string content, string contentType = "application/x-www-form-urlencoded")
        {
            string result = string.Empty;
            try
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));
                    var stringContent = new StringContent(content, Encoding.UTF8);
                    var response = client.PostAsync(url, stringContent).Result;
                    result = response.Content.ReadAsStringAsync().Result;
                }
            }
            catch (Exception e)
            {
                throw new Exception("POST请求错误" + e.ToString());
            }
            return result;
        }

Usage Example

Example #1
0
        public bool VerifyNotify(HttpRequestBase request, out WePayReturnModel model)
        {
            bool verifyResult = false;

            model = new WePayReturnModel();

            string requestXml = GetRequestXmlData(request);
            var    dic        = FromXml(requestXml);

            string returnCode = GetValueFromDic <string>(dic, "return_code");

            if (!string.IsNullOrEmpty(returnCode) && returnCode == "SUCCESS")//通讯成功
            {
                bool result = WePayNotifyValidation(dic);
                if (result)
                {
                    string transactionid = GetValueFromDic <string>(dic, "transaction_id");

                    if (!string.IsNullOrEmpty(transactionid))
                    {
                        string queryXml       = BuildQueryRequest(transactionid, dic);
                        string queryResult    = HTTPHelper.Post(WepayConfig.WEPAY_ORDERQUERY_URL, queryXml);
                        var    queryReturnDic = FromXml(queryResult);

                        if (ValidatonQueryResult(queryReturnDic))//查询成功
                        {
                            verifyResult      = true;
                            model.OutTradeNo  = GetValueFromDic <string>(dic, "out_trade_no");
                            model.TotalFee    = GetValueFromDic <decimal>(dic, "total_fee") / 100;
                            model.TradeNo     = transactionid;
                            model.TradeStatus = GetValueFromDic <string>(dic, "result_code");
                            model.ReturnXml   = BuildReturnXml("OK", "成功");
                        }
                        else
                        {
                            model.ReturnXml = BuildReturnXml("FAIL", "订单查询失败");
                        }
                    }
                    else
                    {
                        model.ReturnXml = BuildReturnXml("FAIL", "支付结果中微信订单号不存在");
                    }
                }
                else
                {
                    model.ReturnXml = BuildReturnXml("FAIL", "签名失败");
                }
            }
            else
            {
                string returnmsg;
                dic.TryGetValue("return_msg", out returnmsg);
                throw new Exception("异步通知错误:" + returnmsg);
            }

            return(verifyResult);
        }
All Usage Examples Of AW.Pay.Core.HTTPHelper::Post
HTTPHelper