0
Answer

HttpwebRequest

tsukimoto

tsukimoto

18y
5.1k
1
Background:
 
I have a form(local) which uploads a video file to a 3rd party. In order for me to do this, I need to pre populate a hidden field in my form with a token. To get this token, I need to make a 2 requests. The 1st request gets a token for the day. This returns a long string. I can complete this part fine!
 
The 2nd request, I need to post to another url but this time I need to pass in the token I received from my first request in order to get my final cryptic token for that specific user.  You with me? SOme how i need to pass the first token via the header or a cookie. neither of them has worked for me.
 
thanks dudes. below is my code

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(_Url);

string proxy = null;

string data = String.Format(_Variables);

byte[] buffer = Encoding.UTF8.GetBytes(data);

req.Method = "POST";

req.ContentType = "text/html";

//req.ContentType = "application/x-www-form-urlencoded";

req.ContentLength = buffer.Length;

req.Proxy = new WebProxy(proxy, true); // ignore for local addresses

req.CookieContainer = new CookieContainer();

try

{

if(_Cookie != null)

{

 

}

Stream reqst = req.GetRequestStream(); // add form data to request stream

reqst.Write(buffer, 0, buffer.Length);

//reqst.Flush();

reqst.Close();

HttpWebResponse res = (HttpWebResponse)req.GetResponse();

string contentRange = res.Headers["Content-Range"];

Stream resst = res.GetResponseStream();

StreamReader sr = new StreamReader(resst);

m_ResponseString = sr.ReadToEnd();

}

catch(ProjException ProjEx)

{

throw new ProjException("HttpRequest.HttpRequest() - Proj Ex", ProjEx);

}

catch(Exception E)

{

throw new ProjException("HttpRequest.HttpRequest() - Norm Ex", E);

}

 
Next Recommended Forum