我目前有一名员工正在执行手动数据输入,方法是从内部开发的应用程序中获取信息并将其输入到基于供应商的应用程序表单中以进行课程注册。在应用程序正式发布之前,这并不是一个真正的问题,现在我们已经有 1300 多个用户需要输入数据。我想要实现的是一个应用程序,它获取我们已经收集的用户信息并自动在供应商网站上提交这些表格。Web 服务或直接访问供应商数据库是不可能的(定价是天文数字),所以我真的需要这种表单自动化工作。这是我目前拥有的代码,但似乎没有得到任何地方。任何输入都会有帮助。
public static string HttpPost(string uri, string parameters)
{
WebRequest req = WebRequest.Create(uri);
string postData = parameters;
byte[] send = Encoding.Default.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = send.Length;
Stream sout = req.GetRequestStream();
sout.Write(send, 0, send.Length);
sout.Flush();
sout.Close();
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string returnvalue = sr.ReadToEnd();
return null;
//// parameters: name1=value1&name2=value2
//WebRequest webRequest = WebRequest.Create(uri);
////string ProxyString =
//// System.Configuration.ConfigurationManager.AppSettings
//// [GetConfigKey("proxy")];
////webRequest.Proxy = new WebProxy (ProxyString, true);
////Commenting out above required change to App.Config
//webRequest.ContentType = "application/x-www-form-urlencoded";
//webRequest.Method = "POST";
//byte[] bytes = Encoding.ASCII.GetBytes(parameters);
//Stream os = null;
//try
//{ // send the Post
// webRequest.ContentLength = bytes.Length; //Count bytes to send
// os = webRequest.GetRequestStream();
// os.Write(bytes, 0, bytes.Length); //Send it
//}
//catch (WebException ex)
//{
// Console.WriteLine("HttpPost: Request error");
// Console.Read();
//}
//finally
//{
// if (os != null)
// {
// os.Close();
// }
//}
//try
//{ // get the response
// WebResponse webResponse = webRequest.GetResponse();
// if (webResponse == null)
// { return null; }
// StreamReader sr = new StreamReader(webResponse.GetResponseStream());
// return sr.ReadToEnd().Trim();
//}
//catch (WebException ex)
//{
// Console.WriteLine("HttpPost: Response error");
// Console.Read();
//}
//return null;
} // end HttpPost