【问题标题】:how to set encoded url from windows application and get decoded url from web form如何从 Windows 应用程序设置编码的 url 并从 Web 表单获取解码的 url
【发布时间】:2019-10-08 15:44:20
【问题描述】:

我有一个用于向托管网站发送短信凭据的 Windows 应用程序。现在我无法从请求的实际 Windows 应用程序中获取全部内容。这是我将 httprequest 发送到网络表单的代码:

string apiUrl = "http://sms.infisms.co.in/API/SendSMS.aspx?UserID="+Userid.Trim()+"&UserPassword="+Pass.Trim()+"&PhoneNumber="+MobileNo.Trim()+"&SenderId="+CBSenderid.Text+"&AccountType=2&MessageType=0&Text="+message.Trim();
                Uri address = new Uri(apiUrl);

                // Create the web request 
                HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

                // Set type to POST 
                request.Method = "GET";
                request.ContentType = "text/xml";
                string result = "";
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    // Get the response stream 
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    // Console application output 
                    result = reader.ReadToEnd();
                }
                if (result.Contains("Invalid") || result.Contains("Authentication"))
                {
                    //  ini =Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + ini;
                    //int charPos = result.IndexOf('!');
                    //string returnText = result.Substring(0, charPos - 1);
                    MessageBox.Show("Error : " + result.ToString());
                }
                else
                {
                    try
                    {
                        long retValue = long.Parse(result.ToString());
                        if (retValue > 0)
                        {
                            WriteToCSVTripReport(c_code + "," + message + "," + MobileNo + "," + responce);
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Error : " + result.ToString());
                    }
                }
            }


if (oledbConn.State == ConnectionState.Open)
                {
                    oledbConn.Close();
                }

这里我刚刚创建了一个带有一些查询字符串变量的 url:

http://sms.infisms.co.in/API/SendSMS.aspx?UserID=airan&UserPassword=airanfin&PhoneNumber=9328823027&SenderId=AIRANF&AccountType=2&MessageType=0&Text=Dear I0225 Dtd 05/22/2019 Your ORD#0063052 in NSECM LICHSGFIN Sell 2200 @ 510.2 ;  ORD#0076134 in NSECM NCC Sell 24000 @ 100 ;  ORD#0062307 in NSECM HDFC Sell 1732 @ 2030.5  Exceuted

在这里我从短信服务器收到消息文本,例如:

Dear T0545 Dtd 05/22/2019 Your ORD

这里出了什么问题...请帮帮我..

【问题讨论】:

    标签: c#-4.0 urlencode asp.net-4.0


    【解决方案1】:

    只需将您的 apiurl 传递给此方法,我们就会得到明确的结果:

    public static string EncodeQueryString(string queryString)
            {
                var array = queryString.Split('&', '=');
                for (int i = 0; i < array.Length; i++)
                {
                    string part = array[i];
                    if (i % 2 == 1)
                    {
                        part = System.Web.HttpUtility.UrlEncode(array[i]);
                        queryString = queryString.Replace(array[i], part);
                    }
                }
                return queryString;
            }
    

    【讨论】:

      猜你喜欢
      • 2016-03-30
      • 2017-09-30
      • 2012-09-10
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      • 2016-03-22
      • 2016-06-23
      • 1970-01-01
      相关资源
      最近更新 更多