如何从URL获取参数
问题描述:
大家好,
我的问题是,
我在我的网站中使用SMS API将短信发送给用户&从用户那里收到
因此,当我发送短信时,它们正确发送了我的代码,因为短信发送是
Hi to Everyone,
my problem is,
I am using the SMS API in my website for sms sending to user & receiving from user
so when i send the sms they are properly send my code is, for sms sending is
string result = "";
WebRequest request = null;
HttpWebResponse response = null;
try
{
String sendToPhoneNumber = ph;
String msg = "12345erfdr";
String userid = "20xxxxx";
String passwd = "rereree";
String url =
"http://SMS/Receive.aspx?method=sendMessage&send_to=" + sendToPhoneNumber + "&msg=" + msg + " &userid=" + userid + "&password=" + passwd + "&v=1.1 & msg_type = TEXT & auth_scheme = PLAIN" + "";
request = WebRequest.Create(url);
//in case u work behind proxy, uncomment the
/*WebProxy proxy = new WebProxy("http://proxy:80/",true);
proxy.Credentials = new NetworkCredential("userId","password", "Domain");
request.Proxy = proxy;*/
// Send the ''HttpWebRequest'' and wait for response.
response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
StreamReader reader = new
System.IO.StreamReader(stream, ec);
result = reader.ReadToEnd();
Console.WriteLine(result);
reader.Close();
stream.Close();
}
catch (Exception exp)
{
Console.WriteLine(exp.ToString());
}
finally
{
if (response != null)
response.Close();
}
&为了接收短信,我将接收短信的页面的URL设置为SMS API响应URL.
&我从页面上这些响应URL获得的参数是,
& for receiving the sms I set the URL of my page on which i receive sms is set to the SMS API Response URL.
& I get the parameter from these response url on my page is,
if (Request.Form["phonecode"] != null)
{
pcode = Request.Form["phonecode"].ToString();
}
但是无法获取这些参数,然后如何获取这些参数?
but these parameter are not get then how to get these paramter?
答
如何从URL获取参数
代替Request.Form
,使用Request.QueryString
来获取URL中定义的参数.Request["fieldname"]
也可以.
如您所说,URL中的参数称为查询字符串.
有关详细信息,请参见此处:使用QueryString在页面之间传递变量 [
How To Get Parameter From URL
Instead ofRequest.Form
, useRequest.QueryString
to get the parameters defined in the URL.Request["fieldname"]
works as well.
As you say, parameters in URL are called as querystring.
Here for details: Passing variables between pages using QueryString[^]
您好rakesh-s-shinde,
试试这个链接 [ ^ ]
希望对您有帮助,
:)
Hi rakesh-s-shinde,
Try this Link[^]
I hope it helps,
:)