Heya,
Im having some trouble with Post/Get. Ive got a web app that accepts a post. This post generates a link to a get request. The application works fine e.g
(.... please bear with me here. its a little difficult for me to describe.)
> open the app in a browser
> enter a number, press submit and go to page with link
> click link to see result
The link would be something like /info?id=12&typr=slir and displays data. I can open up as many new tabs in firefox as I like, copy the link address in, and it shows me the data.
(*1)If I where to open a new browser window and type the generated link into the address bar it contains no data.
*****Thats the background here is my problem*******
Im trying to imitate all this user interaction with c#. The post works fine.
The trouble is when I come to the get part. It returns no data. I think the reason for this is similar to the action in *1. That is, opening the get request link in a different browser.
I think that when I make my get request a new connection is made and the instance no longer exists?
first off, do you think the problem lays where I suggested (the example of opening another window)?
And if so could you suggest a solution?
do i create a proxy?
do i send the post and get with the same stream?
I'd really appreciate any ideas,hypotesis, suggestions. Anything at all
***************Post***************************
string url = " string result = string.Empty;
string postData = "msisdn0=123";
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x- request.ContentLength = postData.Length;
Stream writeStream = request.GetRequestStream();
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
result = readStream.ReadToEnd();
*********************************************************
***************Get***************************
string url2 = " string result2 = string.Empty;
string postData2 = "info?id=862324984&type=slir";
Uri uri2 = new Uri(url2);
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(uri2);
request2.Method = "GET";
request2.ContentType = "application/x- request2.ContentLength = postData2.Length;
Stream writeStream2 = request2.GetRequestStream();
UTF8Encoding encoding2 = new UTF8Encoding();
byte[] bytes2 = encoding.GetBytes(postData2);
writeStream2.Write(bytes, 0, bytes.Length);
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
Stream responseStream2 = response2.GetResponseStream();
StreamReader readStream2 = new StreamReader(responseStream2, Encoding.UTF8);
result2 = readStream.ReadToEnd();
testText.Text = result2;
*********************************************************
Im having some trouble with Post/Get. Ive got a web app that accepts a post. This post generates a link to a get request. The application works fine e.g
(.... please bear with me here. its a little difficult for me to describe.)
> open the app in a browser
> enter a number, press submit and go to page with link
> click link to see result
The link would be something like /info?id=12&typr=slir and displays data. I can open up as many new tabs in firefox as I like, copy the link address in, and it shows me the data.
(*1)If I where to open a new browser window and type the generated link into the address bar it contains no data.
*****Thats the background here is my problem*******
Im trying to imitate all this user interaction with c#. The post works fine.
The trouble is when I come to the get part. It returns no data. I think the reason for this is similar to the action in *1. That is, opening the get request link in a different browser.
I think that when I make my get request a new connection is made and the instance no longer exists?
first off, do you think the problem lays where I suggested (the example of opening another window)?
And if so could you suggest a solution?
do i create a proxy?
do i send the post and get with the same stream?
I'd really appreciate any ideas,hypotesis, suggestions. Anything at all
***************Post***************************
string url = " string result = string.Empty;
string postData = "msisdn0=123";
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x- request.ContentLength = postData.Length;
Stream writeStream = request.GetRequestStream();
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
result = readStream.ReadToEnd();
*********************************************************
***************Get***************************
string url2 = " string result2 = string.Empty;
string postData2 = "info?id=862324984&type=slir";
Uri uri2 = new Uri(url2);
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(uri2);
request2.Method = "GET";
request2.ContentType = "application/x- request2.ContentLength = postData2.Length;
Stream writeStream2 = request2.GetRequestStream();
UTF8Encoding encoding2 = new UTF8Encoding();
byte[] bytes2 = encoding.GetBytes(postData2);
writeStream2.Write(bytes, 0, bytes.Length);
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
Stream responseStream2 = response2.GetResponseStream();
StreamReader readStream2 = new StreamReader(responseStream2, Encoding.UTF8);
result2 = readStream.ReadToEnd();
testText.Text = result2;
*********************************************************