473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

StreamWriter and httpwebrequest

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
Nov 17 '05 #1
2 6752
It is sending data to the url passed to the .Create method.
It encodes the data into a byte array. Then, gets a hold of
RequestStream and uses the StreamWrite to write to it.

Here's another sample that sends data over http
and then gets a response. Look for the Upload
method:

http://www.eggheadcafe.com/articles/...encryption.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net

"Octavio Filipe" <02********@netcabo.pt> wrote in message
news:O1*************@TK2MSFTNGP15.phx.gbl...
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

Nov 17 '05 #2
Octavio Filipe wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
1
by: Vladimir Bezugliy | last post by:
I have a server that listen a socket. And I have next client: TcpClient socketForServer = new TcpClient("IVBEZUGLIY", 21000); NetworkStream networkStream = socketForServer.GetStream();...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
4
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it....
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
6
by: Mike Koerner | last post by:
Hi, I am having problems setting the HttpWebRequest Date header. I understand that it is a restricted header and I do receive the "This header must be modified with the appropriate property." ...
10
by: SpecialKay | last post by:
i got a nice problem here: my page recieves a request, it then sends a request back to the other server with all of the same params as the orignal requess, and waits for a responce the responce...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
I am using HTTPWebRequest to programatically send a HTTP POST request. I have a long string (400 characters): dim str as string = "xxxxx...." It is a value that is passed in the HTTP Post...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.