如何从Windows应用程序设置编码的url并从Web表单获取解码的url

时间:2019-05-22 08:00:15

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

我有一个Windows应用程序,用于将SMS凭据发送到托管网站。现在我无法从请求的实际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();
                }

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

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

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

1 个答案:

答案 0 :(得分:0)

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