I am facing the problem with posting username and password with different domains - one submits the form successfully while the other doesn't(the form data is empty)! The html code on both domains is the same. Here is the sample code- the commented domain doesn't post: Any Help is greatly appreciated!
Note: the domain that runs on nginx posts data successfully while the other on apache doesn't if at all it has got something to do with servers
public class CookieAwareWebClient : System.Net.WebClient
{
private System.Net.CookieContainer Cookies = new System.Net.CookieContainer();
protected override System.Net.WebRequest GetWebRequest(Uri address)
{
System.Net.WebRequest request = base.GetWebRequest(address);
if (request is System.Net.HttpWebRequest)
{
var hwr = request as System.Net.HttpWebRequest;
hwr.CookieContainer = Cookies;
}
return request;
}
}
# Main function
NameValueCollection postData = new NameValueCollection();
postData.Add("username", "abcd");
postData.Add("password", "efgh");
var wc = new CookieAwareWebClient();
//string url = "https://abcd.example.com/service/login/";
string url = "https://efgh.example.com/service/login/";
wc.DownloadString(url);
//writer.WriteLine(wc.ResponseHeaders);
Console.WriteLine(wc.ResponseHeaders);
byte[] results = wc.UploadValues(url, postData);
string text = System.Text.Encoding.ASCII.GetString(results);
Console.WriteLine(text);