Hi, any body can me how to post below form information using Http web request.////.wrapper { width:25.5%; float:left; font-size:0.7em; margin-right:5.5%; text-align:left; } .wrapper p { width:0px; margin:0px; }Not a member yet? Click here to JoinSign in
// //TechNet Edge: Start an IT business in MalaysiaWindowsClient: Silverlight 2 has RTW! (a week ago)WindowsClient: Tales From The PDC - Day 1WindowsClient: I am here at PDC!WindowsClient: Transparent design for ADO.NET Data Services offlineWindowsClient: Designers and DevelopersWindowsClient: Live from PDCChannel 10: Windows Live ID Becomes OpenID ProviderChannel 9: Dave Campbell: Inside SQL ServicesChannel 9: Steve Marx: Windows Azure for DevelopersChannel 9: Manuvir Das: Introducing Windows AzureWindowsClient: ADO.NET Data Services @ PDCChannel 10: Microsoft's Cloud, Part 2: Windows AzureChannel 10: Microsoft’s Cloud, Part 1: Defining The CloudChannel 9: Modeling Through the AgesChannel 10: Digital Media Boot CampTechNet Edge: SharePoint Disaster Recovery with Michael NoelMicrosoft Communities
![]() |
0 |
![]() |
Check below link
Haissam Abdul Malak
MCAD.NET
| Blog |
![]() |
0 |
![]() |
Hi Singhrajankr,
You can use HttpWebRequest and HttpWebResponse as well as some other network I/O code to implement it.
Please refer the following link.
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;public class WebPageReader
{/**/
/// <summary>
/// cookie
/// </summary>
private CookieCollection _Cookies = new CookieCollection();/**/
/// <summary>
/// to keep the same session
/// </summary>
private CookieContainer cookieContainer = new CookieContainer();/**/
/// <summary>
private bool isKeepAlive = false;public bool IsKeepAlive
{
get { return isKeepAlive; }
set { isKeepAlive = value; }
}
public string GetHTML(string URL)
{
return GetHTML(URL, "", System.Text.Encoding.ASCII);
}public string GetHTML(string URL, string PostData)
{
return GetHTML(URL, PostData, System.Text.Encoding.ASCII);
}public string GetHTML(string URL, System.Text.Encoding encoding)
{
return GetHTML(URL, "", encoding);
}/**/
/// <summary>
/// </summary>
/// <param name="URL"></param>
/// <param name="PostData"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public string GetHTML(string URL, string PostData, System.Text.Encoding encoding)
{
isKeepAlive = false;
string _Html = "";HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
if (_Cookies.Count > 0)
{
request.CookieContainer.Add(new Uri(URL), _Cookies);
}
else
{
request.CookieContainer = this.cookieContainer;
}//submit the data
if (PostData != null && PostData.Length > 0)
{
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";byte[] b = encoding.GetBytes(PostData);
request.ContentLength = b.Length;
using (System.IO.Stream sw = request.GetRequestStream())
{
try
{
sw.Write(b, 0, b.Length);
}
catch (Exception ex)
{
throw new Exception("Post Data Error!!", ex);
}
finally
{
if (sw != null) { sw.Close(); }
}
}
}
HttpWebResponse response = null;
System.IO.StreamReader sr = null;try
{response = (HttpWebResponse)request.GetResponse();
_Cookies = response.Cookies;
sr = new System.IO.StreamReader(response.GetResponseStream(), encoding);
_Html = sr.ReadToEnd();
}
catch (WebException webex)
{
if (webex.Status == WebExceptionStatus.KeepAliveFailure)
{
isKeepAlive = true;
}
else
{
throw new Exception("DownLoad Data Error", webex);
}
}
catch (System.Exception ex)
{
throw new Exception("DownLoad Data Error", ex);
}
finally
{
if (sr != null) { sr.Close(); }
if (response != null) { response.Close(); }
response = null;
request = null;
}return _Html;
}
}
Please check the following link.http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2456794&SiteID=1
http://www.codeguru.com/csharp/.net/net_asp/miscellaneous/article.php/c12883
Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |