StreamWriter and httpwebrequest

O

Octavio Filipe

hi there,

could anyone explains to me what this does?


HttpWebRequest httpWebRequestLogin =
HttpWebRequest.Create(LOGIN_URL_LOGIN) as HttpWebRequest;

string postData = String.Format(USERNAME);
Encoding enc = Encoding.GetEncoding("ASCII");
byte[] data = enc.GetBytes(postData);

StreamWriter requestWriter = new
StreamWriter(httpWebRequestLogin.GetRequestStream());
requestWriter.Write(data);
requestWriter.Close();


Thanks in advance,
o.f
 
J

Joerg Jooss

Octavio said:
hi there,

could anyone explains to me what this does?


HttpWebRequest httpWebRequestLogin =
HttpWebRequest.Create(LOGIN_URL_LOGIN) as HttpWebRequest;

string postData = String.Format(USERNAME);
Encoding enc = Encoding.GetEncoding("ASCII");
byte[] data = enc.GetBytes(postData);

StreamWriter requestWriter = new
StreamWriter(httpWebRequestLogin.GetRequestStream());
requestWriter.Write(data); requestWriter.Close();

Note that this way to write to the request stream is rather weird.
Writing an ASCII encoded byte array to a UTF-8 StreamWriter, which has
no concept of writing bytes and happily calls ToString()...

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top