C# - Webclient Post Data Issue - c#

Im try to extract data from a website with webclient but i dont know the exact parameters for the Post and i receive allways empty data.
Website: Red Arrow is the action and on green its the data i want
To see the Post parameters i use Google Ghrome Developer Tools and in the tab "Network" i look for the Post Request Header.
Post Request - Header
My C# code its this:
OLD CODE - This not working with webclient
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
using (WebClient wc = new WebClient())
{
wc.Headers.Add(HttpRequestHeader.Accept, "*/*");
wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2");
wc.Headers.Add(HttpRequestHeader.CacheControl, "no-cache");
//wc.Headers.Add(HttpRequestHeader.Connection, "keep-alive");
//wc.Headers.Add(HttpRequestHeader.ContentLength, "18801");
wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded; charset=UTF-8");
wc.Headers.Add(HttpRequestHeader.Cookie, "_pk_id.70.0919=b6cdc4d1ee3456d0.1456252054.2.1456255268.1456255085.;" + "ASP.NET_SessionId=zlth2slu3o05ek511w5jb4rt");
wc.Headers.Add(HttpRequestHeader.Host, "www.citius.mj.pt");
wc.Headers.Add("Origin", "https://www.citius.mj.pt");
wc.Headers.Add(HttpRequestHeader.Referer, "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx");
wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36");
wc.Headers.Add("X-MicrosoftAjax", "Delta=true");
wc.Headers.Add("X-Requested-With", "XMLHttpRequest");
string parametro1 = "ctl00$ContentPlaceHolder1$ScriptManager1=ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch";
string parametro2 = "ctl00$ContentPlaceHolder1$rbtlTribunais=False";
string parametro3 = "ctl00$ContentPlaceHolder1$ddlTribunais=- Todos os Tribunais -";
string parametro4 = "ctl00$ContentPlaceHolder1$rblDias=todos";
string parametro5 = "__EVENTTARGET=";
string parametro6 = "__EVENTARGUMENT=";
string parametro7 = "__LASTFOCUS=";
string parametro8 = "__VIEWSTATE=/wEPDwULLTE2MDIzOTkyMDcPFg4eCFBhZ2VTaXplAgoeCFdyaXRlTG9naB4OU2VhcmNoQ3JpdGVyaWEyvwMAAQAAAP////8BAAAAAAAAAAwCAAAAS1RyaWJ1bmFpc05ldC5XZWJzaXRlLCBWZXJzaW9uPTIuNC4zLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAPVRyaWJ1bmFpc05ldC5XZWJzaXRlLkRBTC5TZXJ2aWNlcy5WZW5kYUFudW5jaW9zU2VhcmNoQ3JpdGVyaWEDAAAAC19pZFVuT3JnUmVmBV9kaWFzCV9leHRpbnRvcwMDA25TeXN0ZW0uTnVsbGFibGVgMVtbU3lzdGVtLkludDMyLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXW5TeXN0ZW0uTnVsbGFibGVgMVtbU3lzdGVtLkludDMyLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQ5TeXN0ZW0uQm9vbGVhbgIAAAAKCggBAAseC1JlY29yZENvdW50AscJHgpQYWdlTnVtYmVyAgEeC0xhc3RMb3dlcklkZB4LTGFzdFVwcGVySWRkFgJmD2QWAgIDD2QWAgIFD2QWBAIBD2QWAmYPZBYEAgEPEGRkFgFmZAIDDxAPFggeFEFwcGVuZERhdGFCb3VuZEl0ZW1zZx4NRGF0YVRleHRGaWVsZAUETm9tZR4ORGF0YVZhbHVlRmllbGQFCklkVW5PcmdSZWYeC18hRGF0YUJvdW5kZ2QQFb0B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7n5QwCy5D6jw8C77m8+gECm9yEzwgC5rel0AYCypDajw8CqZjBjgoCypCqjw8C0evQkAUC5re10AYCotnY0QgCvMX6pQMCypCyjw8C5re90AYCqJjFjgoCotmg0QgCx8+mzAIC2Y7L5QwCvtnI0QgC8ret0AYC3o7P5QwCpJj5jgoC2Y7f5QwC/bep0AYCl9ygzwgCl9yczwgCudnc0QgCwZD+jw8C/bfJ0AYCp5j5jgoCrOrYkAUCwZD6jw8CwZCyjw8Ci8XmpQMCq+rw0AUCtsWe+gMCtsWS+gMCq+r80AUC+LelkAcCx47HpQ0CopjpzgoCndyAjwkCzJDWzw8CpNnIkQkC2c+mjAMC+onE4wcCheWA7g0CgsPTmQYC8YbIZALotaH2CgLkiaziCQKIwtyjBwKPvOOHBwKn2efXAgKh2ru0BwLkiYifDwKCg+qACwLZ6ZORCAL/wfXjBwL9wcnjBwK5oIOQDALwrqOOCwL3uvOGAtOIyfznMNQ0NVck838xcE7itysvOowRqyKO3jGrE24T";
string parametro10 = "__ASYNCPOST=true";
string parametro11 = "ctl00$ContentPlaceHolder1$btnSearch=Pesquisar";
string parametros = parametro1 + "&" + parametro2 + "&" + parametro3 + "&" + parametro4 + "&" + parametro5 + "&" + parametro6 + "&" + parametro7 + "&" + parametro8 + "&" + parametro9 + "&" + parametro10 + "&" + parametro11;
string HtmlResult = wc.UploadString(URI, parametros);
}
What im doing wrong?
WORKING CODE FROM SAKURA + MYCODE to jump the next page
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
CookieContainer cc = new CookieContainer();
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(URI);
h.CookieContainer = cc;
HttpWebResponse hr = (HttpWebResponse)h.GetResponse();
using (var s = hr.GetResponseStream())
{
using (var r = new StreamReader(s, Encoding.UTF8))
{
string html = r.ReadToEnd();
Match mVS = Regex.Match(html, "id=\"__VIEWSTATE\" value=\"(.*?)\"", RegexOptions.Singleline);
Match mEV = Regex.Match(html, "id=\"__EVENTVALIDATION\" value=\"(.*?)\"", RegexOptions.Singleline);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
//param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$upResultados|ctl00$ContentPlaceHolder1$Pager1$btnNextPage");
param.Add("__EVENTTARGET", "");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__ASYNCPOST", "true");
param.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post = "";
foreach (var i in param)
{
post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
var data = Encoding.UTF8.GetBytes(post);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
int x = 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Dictionary<string, string> param2 = new Dictionary<string, string>();
//param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
param2.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$upResultados|ctl00$ContentPlaceHolder1$Pager1$btnNextPage");
param2.Add("__EVENTTARGET", "");
param2.Add("__EVENTARGUMENT", "");
param2.Add("__LASTFOCUS", "");
param2.Add("__VIEWSTATE", mVS.Groups[1].Value);
param2.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param2.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param2.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param2.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param2.Add("__ASYNCPOST", "true");
//param2.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post2 = "";
foreach (var i in param2)
{
post2 += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
var data2 = Encoding.UTF8.GetBytes(post2);
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(URI);
request2.CookieContainer = cc;
request2.Referer = URI;
request2.Method = "POST";
request2.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request2.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request2.Headers.Add("Origin", "https://www.citius.mj.pt");
request2.Headers.Add("X-Requested-With", "XMLHttpRequest");
request2.Headers.Add("X-MicrosoftAjax: Delta=true");
request2.ContentLength = data2.Length;
using (var stream2 = request2.GetRequestStream())
{
stream2.Write(data2, 0, data2.Length);
}
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd();
int y = 2;
}
}

The problem is you not encode the POST data when you send back to server. You can use WebUtility.UrlEncode to endode them.
Here is modify of your code:
Note: wrap second request functions in using like the first request I do for you:
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
CookieContainer cc = new CookieContainer();
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(URI);
h.CookieContainer = cc;
HttpWebResponse hr = (HttpWebResponse)h.GetResponse();
using (var s = hr.GetResponseStream())
{
using (var r = new StreamReader(s, Encoding.UTF8))
{
string html = r.ReadToEnd();
//Console.WriteLine(html);
Match mVS = Regex.Match(html, "id=\"__VIEWSTATE\" value=\"(.*?)\"", RegexOptions.Singleline);
//Console.WriteLine(mVS.Groups[1].Value);
Match mEV = Regex.Match(html, "id=\"__EVENTVALIDATION\" value=\"(.*?)\"", RegexOptions.Singleline);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
param.Add("__EVENTTARGET", "");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__ASYNCPOST", "true");
param.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post = "";
foreach (var i in param) post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
var data = Encoding.UTF8.GetBytes(post);
Console.WriteLine(data.Length);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(responseString);
}
}

Related

HttpWebResponse returns wrong html

For get bitcoin price i did this :
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.blockchain.com/prices");
req.Method = "GET";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
req.ContentType = "text/html; charset=utf-8";
req.Referer = "";
req.KeepAlive = true;
req.Timeout = 25000;
req.AllowAutoRedirect = false;
CookieContainer cookieJar1 = new CookieContainer();
req.CookieContainer = cookieJar1;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
foreach (Cookie cookie in res.Cookies)
{
cookieJar1.Add(new Cookie(cookie.Name.Trim(), cookie.Value.Trim(), "/", cookie.Domain));
}
Stream Stream = res.GetResponseStream();
StreamReader reader = new StreamReader(Stream);
string reader_str = reader.ReadToEnd();
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(reader_str);
HtmlAgilityPack.HtmlNode node = htmlDoc.DocumentNode.SelectSingleNode("//p[#title='Bitcoin']");
string bitcoin_price_str = node.InnerText.Trim().Replace(",", "");
bitcoin_price = double.Parse(bitcoin_price_str);
reader.Close();
Stream.Close();
res.Close();
The reader_str is like this :
https://pastebin.com/jT66GzmA
Why reader_str has wrong html?
How can i fix this problem?

Sign up instagram Using C#

so im working on an instagram tool. i need to Create an account with HttpWebRequest but somethings wrong with my code and it doesnt work here is the Code:
username = "something";
password = "something";
mail = " something#mail.com";
name = "something";
string postData = "email=" + mail + "&password=" + password + "&enc_password=%23PWD_INSTAGRAM_BROWSER%3A6%3A1583227313%3AAXFQANTXAGE5jwEKNbpJbvot0SGTp%2Bq7a0ckELnuYQnQLIJa2Th6UwIqdknx%2FDa8R7q1%2F2Bt4scBUrh%2B1aFDKL0H%2Fut5cyi3w1sIEPa1keAuNcNj9nAXo1oFzUYMhCGVB7qerse5hQfMjTVjNa4%3D&username=" + username + "&first_name=" + name + "&seamless_login_enabled=1&tos_version=row&opt_into_one_tap=false";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.instagram.com/accounts/emailsignup/");
byte[] postBytes = Encoding.ASCII.GetBytes(postData);
req.ContentLength = postBytes.Length;
req.CookieContainer = new CookieContainer();
req.Method = "POST";
req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36";
req.Accept = "*/*";
req.ContentType = "application/x-www-form-urlencoded";
req.Referer = "https://www.instagram.com/accounts/emailsignup/";
req.Headers["Accept-Language"] = "de,en-US;q=0.7,en;q=0.3";
req.Headers["Accept-Encoding"] = "gzip, deflate";
req.Headers["X-Requested-With"] = "XMLHttpRequest";
Stream dataStream = req.GetRequestStream();
dataStream.Write(postBytes, 0, postBytes.Length);
dataStream.Flush();
dataStream.Close();
HttpWebResponse webResp = (HttpWebResponse)req.GetResponse(); //error in this line---> The remote server returned an error: (403) Forbidden.
Stream datastream = webResp.GetResponseStream();
StreamReader reader = new StreamReader(datastream);
string s = reader.ReadToEnd();
Console.WriteLine(s);

C# - HttpWebRequest Get Data Next Page(s) Issue

Im try to extract data from a website with httpwebrequest. Im able to extract data from the first "Page" but when i try to get data to the next or previous page i get a error.
Next Page Action - Click on the number page
To see the Post parameters i use Fiddler to compare the Post Request Header from my Code and the website.
Post Request - Header 2ºPage
My actual C# code its this:
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
CookieContainer cc = new CookieContainer();
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(URI);
h.CookieContainer = cc;
HttpWebResponse hr = (HttpWebResponse)h.GetResponse();
using (var s = hr.GetResponseStream())
{
using (var r = new StreamReader(s, Encoding.UTF8))
{
string html = r.ReadToEnd();
Match mVS = Regex.Match(html, "id=\"__VIEWSTATE\" value=\"(.*?)\"", RegexOptions.Singleline);
Match mEV = Regex.Match(html, "id=\"__EVENTVALIDATION\" value=\"(.*?)\"", RegexOptions.Singleline);
///////////////////////////////////////SEARCH///////////////////////////////////////////////////
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
param.Add("__EVENTTARGET", "");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__ASYNCPOST", "true");
param.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post = "";
foreach (var i in param)
{
post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
var data = Encoding.UTF8.GetBytes(post);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.Headers.Add("Cache-Control", "no-cache");
request.Accept = "*/*";
request.Headers.Add("Accept-Language", "pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
int x = 1;
////////////////////////////////////////////NEXT PAGE//////////////////////////////////////////
param.Clear();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$upResultados|ctl00$ContentPlaceHolder1$Pager1$lnkNext");
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__EVENTTARGET", "ctl00$ContentPlaceHolder1$Pager1$lnkNext");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("__ASYNCPOST", "true");
post = "";
foreach (var i in param)
{
post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
data = Encoding.UTF8.GetBytes(post);
request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.Headers.Add("Cache-Control", "no-cache");
request.Accept = "*/*";
request.Headers.Add("Accept-Language", "pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
response = (HttpWebResponse)request.GetResponse();
responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
int y = 1;
}
}
The result i get when i trying to get nextpage data its:
Result from fiddler
Comparing the header between calls from my code and the website the only difference i see its the "_EVENTEVALUATION".
What im doing wrong?
As I suggest, you should split response string.
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
CookieContainer cc = new CookieContainer();
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(URI);
h.CookieContainer = cc;
HttpWebResponse hr = (HttpWebResponse)h.GetResponse();
using (var s = hr.GetResponseStream())
{
using (var r = new StreamReader(s, Encoding.UTF8))
{
string html = r.ReadToEnd();
Match mVS = Regex.Match(html, "id=\"__VIEWSTATE\" value=\"(.*?)\"", RegexOptions.Singleline);
Match mEV = Regex.Match(html, "id=\"__EVENTVALIDATION\" value=\"(.*?)\"", RegexOptions.Singleline);
///////////////////////////////////////SEARCH///////////////////////////////////////////////////
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
param.Add("__EVENTTARGET", "");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__ASYNCPOST", "true");
param.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post = "";
foreach (var i in param)
{
post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
var data = Encoding.UTF8.GetBytes(post);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.Headers.Add("Cache-Control", "no-cache");
request.Accept = "*/*";
request.Headers.Add("Accept-Language", "pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
File.WriteAllText("D:\\tmp1.txt", responseString);
////////////////////////////////////////////NEXT PAGE//////////////////////////////////////////
param.Clear();
string[] split = responseString.Split('|');
for (int i = 0; i < split.Length; i++)
{
if (split[i] == "__VIEWSTATE") param.Add("__VIEWSTATE", split[i + 1]);
if (split[i] == "__EVENTVALIDATION") param.Add("__EVENTVALIDATION", split[i + 1]);
}
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$upResultados|ctl00$ContentPlaceHolder1$Pager1$lnkNext");
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__EVENTTARGET", "ctl00$ContentPlaceHolder1$Pager1$lnkNext");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
//param.Add("__VIEWSTATE", mVS.Groups[1].Value);
//param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("__ASYNCPOST", "true");
post = "";
foreach (var i in param)
{
post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
data = Encoding.UTF8.GetBytes(post);
request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.Headers.Add("Cache-Control", "no-cache");
request.Accept = "*/*";
request.Headers.Add("Accept-Language", "pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
response = (HttpWebResponse)request.GetResponse();
responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
File.WriteAllText("D:\\tmp2.txt", responseString);
int y = 1;
}
}

Cannot login in web app via C#

I'm trying to log in at http://carkit.kg (django app) via C# with following code
HttpWebRequest tokenRequest = (HttpWebRequest)WebRequest.Create("http://carkit.kg");
tokenRequest.CookieContainer = new CookieContainer();
string token = "";
using (var response = (HttpWebResponse)tokenRequest.GetResponse()) {
token = response.Cookies["csrftoken"].ToString().Split('=')[1];
}
HttpWebRequest loginRequest = (HttpWebRequest)WebRequest.Create("http://carkit.kg");
var cache = new CredentialCache();
cache.Add(new Uri("http://carkit.kg"), "Basic", new NetworkCredential(username, password));
loginRequest.Credentials = cache;
loginRequest.PreAuthenticate = true;
loginRequest.Method = "POST";
loginRequest.CookieContainer = new CookieContainer();
loginRequest.CookieContainer.Add(new Cookie("csrftoken", token) {Domain="carkit.kg"});
Debug.Log(token);
byte[] data = Encoding.ASCII.GetBytes("username=" + username + "&password=" + password + "&csrfmiddlewaretoken=" + token);
loginRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
loginRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
loginRequest.Headers.Add("Cache-Control", "max-age=0");
loginRequest.Headers.Add("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
//loginRequest.ContentType = "application/x-www-form-urlencoded";
loginRequest.Headers.Add("Origin", "http://carkit.kg");
loginRequest.Referer = "http://carkit.kg/";
loginRequest.Headers.Add("UpgradeInsecureRequests", "1");
loginRequest.Headers.Add("XCompress", "null");
loginRequest.Headers.Add("ContentType", "application/x-www-form-urlencoded");
loginRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
loginRequest.Headers.Add("X-CSRFToken",token);
loginRequest.ContentLength = data.Length;
loginRequest.Timeout = 3000;
loginRequest.GetRequestStream().Write(data, 0, data.Length);
loginRequest.Headers.Add("X-CSRFToken", token);
HttpWebResponse authResponse = (HttpWebResponse)loginRequest.GetResponse();
Debug.Log(authResponse.ResponseUri);
Both requests running well, but last line returns incorrect uri (if login is correct it should redirect me to /game and stay at / in other case) - anyway it returns /. Redirect is enabled and you see which headers I've included into request. What is the problem?
I've just used django-rest-framework as authentication service and LogIn method got this representation:
public void LogIn(string username, string password)
{
var request = (HttpWebRequest)WebRequest.Create("http://carkit.kg/api/v1/auth/login/");
var postData = "username=" + username;
postData += "&password=" + password;
var data = Encoding.UTF8.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
try {
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK) {
// Successful login
}
else {
serverMessenger.SendErrorMessage(0);
Debug.LogError("Cannot Find User. TryToLogin finished");
}
} catch (WebException e) {
serverMessenger.SendErrorMessage(0);
Debug.LogError("Cannot Find User. TryToLogin finished");
}
}

I cannot get cookie from C# HTTPWebRequest

I have a requirement to get cookies from login because i will apply this cookie in the same page. Here is my code
string boundary = "41184676334";
string username = "username";
string password = "password";
string login_post_data =
"POSTDATA=-----------------------------" + boundary +
"\nContent-Disposition: form-data; name=\"login\"" +
"\n\n" + username +
"\n-----------------------------" + boundary +
"\nContent-Disposition: form-data; name=\"key\"" +
"\n\n" + password +
"\n-----------------------------" + boundary +
"\nContent-Disposition: form-data; name=\"clcode\"" +
"\n\n" +
"\n-----------------------------" + boundary + "--";
var cookies = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://site.com/cgi-bin/login.pl?logout");
request.CookieContainer = cookies;
request.Method = "POST";
request.ContentType = "multipart/form-data; boundary=---------------------------" + boundary;
request.Host = "site.com";
request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Referer = "https://site.com/cgi-bin/login.pl?logout";
//request.Headers.Add("POSTDATA", post_data);
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(StrToByteArray(login_post_data), 0, StrToByteArray(login_post_data).Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
string temp = reader.ReadToEnd();
richTextBox1.Text = temp;
}
foreach (string c in response.Cookies)
{
listBox1.Items.Add(c);
}
The thing is "https://site.com/cgi-bin/login.pl?logout" is the same page after i logged in and i need to pass the cookie
It looks like you try to log in and log out at the same time with your request, sent to URL
https://site.com/cgi-bin/login.pl?logout
Remove the ?logout parameter and try again. Please update your question if it doesn't change anything.
Please explain further, what you're trying to achieve, so we can discuss if the code is correct.

Categories

Resources