hi to all, please help me for Posting data from one asp.net website to another asp.net website, i have use http-post method with cookies, but i cannont post data to file-uploader, please help me for posting the data to a page of another page (and at the another page at which i have to post data there are ,two textboxes,one file-uploader, two drop-downlists and one submit button).
thanks in advance.
My used Code----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
public partial class nurse : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cvbrowserPostData();
}
public void cvbrowserPostData()
{
string ResumePath = Server.MapPath("Doc1.docx");
string boundary = Guid.NewGuid().ToString();
CookieContainer cookies = new CookieContainer();
string url = "https://www.test.com/JobSeeker/PostNewResume.aspx?sslRedirectCnt=1";
string resume = Server.MapPath("Doc1.docx");
HttpWebRequest request = HttpWebRequest.Create(url)
as HttpWebRequest;
request.Method = "POST";
request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
request.PreAuthenticate = true;
request.CookieContainer = cookies;
StringBuilder sb = new StringBuilder();
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:tbJobTitle\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("developer");
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:tbLocation\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("sw13 9ru");
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"btnContinue\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("Continue");
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:newFileUpload:inputResumeUpload\"; filename=\"" + Path.GetFileName(resume) + "\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Type: application/msword");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
using (FileStream fs = new FileStream(resume, FileMode.Open, FileAccess.Read))
{
byte[] contents = new byte[fs.Length];
fs.Read(contents, 0, contents.Length);
sb.Append(Encoding.Default.GetString(contents));
}
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; id=\"spanFilename\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("test.docx");
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:TargetLevel1:ddlLevel\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("SNCAREERLEVEL0");
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:TargetSpecialism1:ddlSpecialism\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("SNSPECIALISM0");
sb.AppendFormat("\r\n");
sb.AppendFormat("--{0}", boundary);
sb.AppendFormat("\r\n");
sb.AppendFormat("Content-Disposition: form-data; name=\"btnContinue\"");
sb.AppendFormat("\r\n");
sb.AppendFormat("\r\n");
sb.AppendFormat("Continue");
sb.AppendFormat("\r\n");
byte[] fulldata = Encoding.Default.GetBytes(sb.ToString());
request.ContentLength = fulldata.Length;
using (Stream sw = request.GetRequestStream())
{
sw.Write(fulldata, 0, fulldata.Length);
}
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
HttpContext.Current.Response.Write(sr.ReadToEnd());
string ss = sr.ReadToEnd();
}
}
}