Powered By Blogger

Search

Thursday, June 5, 2008

Post Data to Other website use Asp.net

Post Data to Other website use Asp.net

Programmatically full up other site textboxes and submit that page using asp.net

String strresponse="";
String postData = "login=user&password=pass123";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);


HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.test.com/login.aspx");


request.Method = "POST";
request.Accept = "test/html";
request.AllowAutoRedirect = true;
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;

request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream();

newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();

request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream receiveStream = response.GetResponseStream();

StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);


strresponse = readStream.ReadToEnd();

Response.Write(strresponse);
readStream.Close();
response.Close();

No comments: