Click here to Skip to main content
15,886,002 members
Home / Discussions / C#
   

C#

 
AnswerRe: After Call Through WebAPI, Entity Is Null Pin
Kevin Marois5-Aug-14 12:40
professionalKevin Marois5-Aug-14 12:40 
QuestionRe: After Call Through WebAPI, Entity Is Null Pin
Richard Deeming6-Aug-14 1:33
mveRichard Deeming6-Aug-14 1:33 
Questioni don't know at what is zed using in this code the ''if(mode == 'c')",pls help! Pin
Alex Sturza5-Aug-14 5:41
Alex Sturza5-Aug-14 5:41 
AnswerRe: i don't know at what is zed using in this code the ''if(mode == 'c')",pls help! Pin
Dilan Shaminda5-Aug-14 5:49
professionalDilan Shaminda5-Aug-14 5:49 
GeneralRe: i don't know at what is zed using in this code the ''if(mode == 'c')",pls help! Pin
Alex Sturza5-Aug-14 6:17
Alex Sturza5-Aug-14 6:17 
GeneralRe: i don't know at what is zed using in this code the ''if(mode == 'c')",pls help! Pin
Dilan Shaminda5-Aug-14 6:34
professionalDilan Shaminda5-Aug-14 6:34 
AnswerRe: i don't know at what is zed using in this code the ''if(mode == 'c')",pls help! Pin
Pete O'Hanlon5-Aug-14 5:49
mvePete O'Hanlon5-Aug-14 5:49 
QuestionWebRequest with Cookie and Post data real life question - code included Pin
KergalBerlin5-Aug-14 3:25
KergalBerlin5-Aug-14 3:25 
Hello community,

In advance, please excuse my lack of knowledge regarding the following topic, I have tried to familiarise myself with the topic using both google and the search function.

A friend of mine asked whether I could get data from a specific website for him, I answered "yes, I can try". I feel like I am pretty close and only need a final push. So let's go:

www.regelleistung.net -> this is the website in question

Menu item : Data for Control Reserve - in the following form he would normally specify what kind of data he is interested in and would then click the submit button .

Someone gave me the TAMPER information for the post request and I came up with the following code:

1. The request requires a jsession cookie which I retrieve + from TAMPER I saw that I require several other items of interest : __fp , _sourcePage and CSRFToken.
Because I do not know how to get those information without making an actual request - I just perform a testrequest and populate an array, which I will use for the actual request


BASEURL = @"https://www.regelleistung.net/ip/action/abrufwert";

C#
public string[] ReceiveCookiesAndHiddenData()
        {
            string[] tempHidden = new string[4];
            HttpWebRequest tempRequest = (HttpWebRequest)WebRequest.Create(BASEURL);
            
            using (HttpWebResponse tempResponse = (HttpWebResponse)tempRequest.GetResponse()) 
            {
                HtmlDocument doc = new HtmlDocument();
                doc.Load(tempResponse.GetResponseStream());

                tempHidden[0] = doc.DocumentNode.SelectNodes("//input[@type='hidden' and @name='_sourcePage']")[0].Attributes["Value"].Value;
                tempHidden[1] = doc.DocumentNode.SelectNodes("//input[@type='hidden' and @name='__fp']")[0].Attributes["Value"].Value;
                tempHidden[2] = doc.DocumentNode.SelectNodes("//input[@type='hidden' and @name='CSRFToken']")[0].Attributes["Value"].Value;
                tempHidden[3] = tempResponse.Headers["Set-Cookie"].Split(new Char[] { ';' })[0];
            }
            return tempHidden;
        }


2. No I have to make the actual request. which requires the following information (according to Tamper):

http://pl.vc/3f5z0[^]


C#
public void MakeActualRequest() 
        {
            hiddenData = ReceiveCookiesAndHiddenData();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(BASEURL);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Referer = "https://www.regelleistung.net/ip/action/abrufwert";
            request.Headers.Add("Set-Cookie",hiddenData[3]);

            NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);
            outgoingQueryString.Add("von", "05.08.2014");
            outgoingQueryString.Add("uenbld", "STXs440zwks=");
            outgoingQueryString.Add("produkt", "MRL");
            outgoingQueryString.Add("work", "anzeigen");
            outgoingQueryString.Add("_sourcePage", hiddenData[0]);
            outgoingQueryString.Add("__fp", hiddenData[1]);
            outgoingQueryString.Add("CSRFToken", hiddenData[2]);
            string postdata = outgoingQueryString.ToString();

            byte[] data = Encoding.ASCII.GetBytes(postdata);
            request.ContentLength = data.Length;

            using(Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(data,0,data.Length);
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();

            using(StreamReader reader = new StreamReader(responseStream, Encoding.Default))
	        {
		        string content = reader.ReadToEnd();
	        }
        }


I receive a WeException "Remote server error :(403)" in this line of code:
C#
HttpWebResponse response = (HttpWebResponse)request.GetResponse();



I would be thankfull for help. I know this is like the 1000000 time such a question has been posted, but I read all those threads and still cannot figure it out.

Thank you all!
AnswerRe: WebRequest with Cookie and Post data real life question - code included Pin
Bernhard Hiller5-Aug-14 20:57
Bernhard Hiller5-Aug-14 20:57 
GeneralRe: WebRequest with Cookie and Post data real life question - code included Pin
KergalBerlin5-Aug-14 21:23
KergalBerlin5-Aug-14 21:23 
QuestionWhat is the main objective of using bar code Pin
Tridip Bhattacharjee4-Aug-14 21:51
professionalTridip Bhattacharjee4-Aug-14 21:51 
AnswerRe: What is the main objective of using bar code PinPopular
OriginalGriff4-Aug-14 22:30
mveOriginalGriff4-Aug-14 22:30 
GeneralRe: What is the main objective of using bar code Pin
Tridip Bhattacharjee5-Aug-14 4:21
professionalTridip Bhattacharjee5-Aug-14 4:21 
GeneralRe: What is the main objective of using bar code Pin
OriginalGriff5-Aug-14 4:27
mveOriginalGriff5-Aug-14 4:27 
Questioncreate vcf contact file Pin
Jassim Rahma4-Aug-14 20:56
Jassim Rahma4-Aug-14 20:56 
AnswerRe: create vcf contact file Pin
Richard MacCutchan4-Aug-14 21:02
mveRichard MacCutchan4-Aug-14 21:02 
AnswerRe: create vcf contact file Pin
Ravi Bhavnani5-Aug-14 6:50
professionalRavi Bhavnani5-Aug-14 6:50 
GeneralRe: create vcf contact file Pin
Jassim Rahma5-Aug-14 20:29
Jassim Rahma5-Aug-14 20:29 
GeneralRe: create vcf contact file Pin
Ravi Bhavnani6-Aug-14 2:17
professionalRavi Bhavnani6-Aug-14 2:17 
GeneralRe: create vcf contact file Pin
Jassim Rahma6-Aug-14 2:23
Jassim Rahma6-Aug-14 2:23 
GeneralRe: create vcf contact file Pin
Ravi Bhavnani6-Aug-14 2:27
professionalRavi Bhavnani6-Aug-14 2:27 
GeneralRe: create vcf contact file Pin
Dave Kreskowiak6-Aug-14 2:29
mveDave Kreskowiak6-Aug-14 2:29 
GeneralRe: create vcf contact file Pin
Jassim Rahma6-Aug-14 2:36
Jassim Rahma6-Aug-14 2:36 
GeneralRe: create vcf contact file Pin
Dave Kreskowiak6-Aug-14 6:38
mveDave Kreskowiak6-Aug-14 6:38 
QuestionRetrieve information from UDL file Pin
Ashfaque Hussain4-Aug-14 20:26
Ashfaque Hussain4-Aug-14 20:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.