POST方法参数 [英] POST method parameters
本文介绍了POST方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码使用POST方法传递参数。任何人都可以帮助我们使用WCF服务读取POST方法参数。
调用方法的代码。
string url = http: // 90.0.0.88/xxx/Service.svc/Getlogin;
StringBuilder postData = new StringBuilder();
postData.Append( userName = + HttpUtility.UrlEncode( xxx)+ &);
postData.Append( password = + HttpUtility.UrlEncode( yyy));
// 所有表单元素的ETC
// 现在发送数据。
StreamWriter writer = null ;
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(url);
request.Method = POST;
request.ContentType = application / x-www-form-urlencoded;
request.ContentLength = postData.ToString()。Length;
尝试
{
writer = new StreamWriter (request.GetRequestStream());
writer.Write(postData.ToString());
}
最后
{
如果(作家!= null )
writer.Close();
}
[edit]已添加代码块 - OriginalGriff [/ edit]
解决方案
我们可以使用输入流来阅读。
string inputStr = new StreamReader(输入).ReadToEnd();
public void Getlogin(流输入)
{
string inputStr = new StreamReader(输入).ReadToEnd();
}
如果是应用程序或网站,我们可以使用请求对象读取普通查询字符串。
Request.Params [ 索引];
The below code to pass the parameters using POST method. Can any one help us to read the POST method parameters using WCF service.
Code to invoke a method.
string url = http://90.0.0.88/xxx/Service.svc/Getlogin";
StringBuilder postData = new StringBuilder();
postData.Append("userName=" + HttpUtility.UrlEncode("xxx") + "&");
postData.Append("password=" + HttpUtility.UrlEncode("yyy"));
//ETC for all Form Elements
// Now to Send Data.
StreamWriter writer = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.ToString().Length;
try
{
writer = new StreamWriter(request.GetRequestStream());
writer.Write(postData.ToString());
}
finally
{
if (writer != null)
writer.Close();
}
[edit]Code block added - OriginalGriff[/edit]
解决方案
We can read by using input stream.
string inputStr = new StreamReader(input).ReadToEnd(); public void Getlogin (Stream input) { string inputStr = new StreamReader(input).ReadToEnd(); }
if application or site, we can read like normal query string using request object.
Request.Params["Index"];
这篇关于POST方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文