Http发布到WML页面 [英] Http post to a WML page
问题描述
我正在使用HttpWebRequest / HttpWebResponse从.net发布数据。到wml页面。 字符串 I am using HttpWebRequest/HttpWebResponse to post data from .net. to a wml page. string firstname = Request.QueryString [ < span style ="font-size:x-small; color:#a31515"> " FirstName" firstname = Request.QueryString["FirstName"];
string lastname = Request.QueryString [ " LastName" ]; string lastname = Request.QueryString["LastName"];
试试 { BlackBerryPOC。 BlackBerryPOC. PostSubmitter post = new BlackBerryPOC。 PostSubmitter (); post.Url = PostSubmitter post = new BlackBerryPOC.PostSubmitter();
post.Url = " http://wportal.bankofamerica.com:80 / Controller / ControllerServlet" ; post.PostItems.Add( "http://wportal.bankofamerica.com:80/Controller/ControllerServlet";
post.PostItems.Add( " lastName" ,姓氏;; post.PostItems.Add( "lastName", lastname);
post.PostItems.Add( " firstName" ,firstname); post.Type = BlackBerryPOC。 "firstName", firstname);
post.Type = BlackBerryPOC. PostSubmitter 。 PostTypeEnum 。发布; PostSubmitter.PostTypeEnum.Post;
string result = post.Post(); } string result = post.Post();
} catch ( 例外 ex) { catch (Exception ex)
{ } public class PostSubmitter class PostSubmitter { /// < span style ="font-size:x-small; color:#008000"> /// <summary> /// 确定要执行的帖子类型。 /// determines what type of post to perform. /// < / summary> /// </summary> 公共 enum PostTypeEnum public enum PostTypeEnum { /// <summary> /// 是否违反来源。 /// Does a get against the source. /// <跨度style ="font-size:x-small; color:#808080">< / summary> /// </summary> 获取, /// < summary> /// <summary> /// 是否有帖子反对来源。 /// Does a post against the source. /// < / summary> /// </summary> 发布 } private string m_url = string 。空; private string m_url = string.Empty;
私人 NameValueCollection m_values = new NameValueCollection (); private NameValueCollection m_values = new NameValueCollection();
private PostTypeEnum m_type = PostTypeEnum 。获取; private PostTypeEnum m_type = PostTypeEnum.Get;
/// < summary> /// <summary> /// 默认构造函数。 /// Default constructor. /// < / summary> /// </summary> public PostSubmitter() { public PostSubmitter()
{ } /// <总结> 跨度> /// <summary> /// 接受url作为参数的构造函数 /// Constructor that accepts a url as a parameter /// < / summary> /// </summary> /// < param name =" url" > 网址将提交帖子的位置。 < / param> /// <param name="url">The url where the post will be submitted to.</param> public PostSubmitter( 字符串 url) : public PostSubmitter(string url)
: 此 () { this()
{ m_url = url; m_url = url; } < span style ="font-size:x-small; color:#808080"> /// /// <summary> /// 允许设置网址和项目的构造函数。 /// Constructor allowing the setting of the url and items to post. /// < / summary> /// </summary> /// < param name =" url"> 帖子的网址。跨度> 跨度> < / param> /// <param name="url">the url for the post.</param> // / < param name ="值"> 帖子的值。 < / param> /// <param name="values">The values for the post.</param> public PostSubmitter( 字符串 url, NameValueCollection 值) : public PostSubmitter(string url, NameValueCollection values)
: 此 (url) { this(url)
{ m_values = values; m_values = values; } /// < summary> /// <summary> /// 获取或设置提交帖子的网址。 /// Gets or sets the url to submit the post to. /// < / summary> /// </summary> public string Url { public string Url
{ get { return m_url; } return m_url;
} set { m_url = value ; } value;
} } /// < summary> /// <summary> /// 获取或设置要发布的项目的名称值集合。 /// Gets or sets the name value collection of items to post. /// < / summary> /// </summary> public NameValueCollection PostItems { public NameValueCollection PostItems
{ 获取 { return m_values; } return m_values;
} set { m_values = m_values = value ; } value;
} } /// < summary> /// <summary> /// 获取或设置要对网址执行的操作类型。 /// Gets or sets the type of action to perform against the url. /// < / summary> /// </summary> 公共 PostTypeEnum 输入 { public PostTypeEnum Type
{ get { return m_type; } return m_type;
} set { m_type = value ; } value;
} } /// < summary> /// <summary> /// 将提供的数据发布到指定的网址。 /// Posts the supplied data to specified url. /// < / summary> /// </summary> /// < returns> 包含帖子结果的字符串。 < / returns> /// <returns>a string containing the result of the post.</returns> 公共 string Post() { public string Post()
{ StringBuilder parameters = 新 StringBuilder () ; StringBuilder parameters = new StringBuilder();
<温泉n style ="font-size:x-small; color:#0000ff"> for { for (int i = 0; i < m_values.Count; i++)
{ EncodeAndAddItem( EncodeAndAddItem( ref 参数,m_values.GetKey(i),m_values [i]); } ref parameters, m_values.GetKey(i), m_values[i]);
} string result = PostData(m_url,parameters.ToString()); string result = PostData(m_url, parameters.ToString());
返回 结果; } return result;
} /// < summary> /// <summary> /// 发布提供的数据到指定的网址。 /// Posts the supplied data to specified url. /// </summary> /// <param name="url">The url to post to.</param> /// <returns>a string containing the result of the post.</returns> public string Post(string url) { public string Post(string url)
{ m_url = url; m_url = url; return this.Post(); } return this.Post();
} /// <summary> /// Posts the supplied data to specified url. /// </summary> /// <param name="url">The url to post to.</param> /// <param name="values">The values to post.</param> /// <returns>a string containing the result of the post.</returns> public string Post(string url, NameValueCollection values) { public string Post(string url, NameValueCollection values)
{ m_values = values; m_values = values; return this.Post(url); } return this.Post(url);
} /// <summary> /// Posts data to a specified url. Note that this assumes that you have already url encoded the post data. /// </summary> /// <param name="postData">The data to post.</param> /// <param name="url">the url to post to.</param> /// <returns>Returns the result of the post.</returns> private string PostData(string url, string postData) { private string PostData(string url, string postData)
{ HttpWebRequest request = null; HttpWebRequest request = null;
if (m_type == PostTypeEnum.Post) { if (m_type == PostTypeEnum.Post)
{ Uri uri = new Uri(url); request = ( Uri uri = new Uri(url);
request = ( HttpWebRequest)WebRequest.Create(uri); request.Method = HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST"; request.ContentType = "POST";
request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; "application/x-www-form-urlencoded";
request.ContentLength = postData.Length; request.Timeout = 1200000; request.Timeout = 1200000; using (Stream writeStream = request.GetRequestStream()) { using (Stream writeStream = request.GetRequestStream())
{ UTF8Encoding encoding = new UTF8Encoding(); UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData); writeStream.Write(bytes, 0, bytes.Length); byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length); } } else { Uri uri = new Uri(url + "?" + postData) ; request = ( Uri uri = new Uri(url + "?" + postData);
request = ( HttpWebRequest)WebRequest.Create(uri); request.Method = HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET"; } "GET";
} string result = string.Empty; string result = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{ using (Stream responseStream = response.GetResponseStream()) { using (Stream responseStream = response.GetResponseStream())
{
我收到内部服务器错误500.
需要知道为什么我收到内部服务器错误。
它是它因为错误填写的请求。
以下是我的代码。
这是呼叫类。
I am getting internal server error 500.
Need to know why i am getting internal server error.
IS it becasue of wrongly populated request.
Below is my code.
///This is calling class.