如何从 windows 应用程序设置编码 url 并从 Web 表单解码 url

how to set encoded url from windows application and get decoded url from web form

我有一个 windows 应用程序可以将短信凭据发送到托管网站。现在我无法从请求的实际 windows 应用程序中获取完整内容。这是我将 httprequest 发送到 Web 表单的代码:

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

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

只需将您的 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;
        }