473,499 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WEBREQUEST AND WEBRESPONSE PROBLEM

I have a vb.net web application. I want to post some variables to another
web page and take some values back and process them.
This is codes in my target url. I should post "langpair" cariable to my
target url and it will respond with a value depend on a value which i send.
<SELECT name=langpair><OPTION
value=en|de>English to German</OPTION><OPTION
value=en|es>English to Spanish</OPTION>
</select>

I must use post method. I must give a value for select object and post it to
my target url ? I heard about BeginGetRequestStream but i dont know how to
do it ?
Dim objURI As Uri = New Uri("http://www.isbuluyorum.com/translate")
Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
objWebRequest.ContentType = "text/html; charset=utf-8"
objWebRequest.Method = "POST"
'BEFORE to get response i should post variables to other web page ?
Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
Dim objStream As Stream = objWebResponse.GetResponseStream()
Dim objStreamReader As StreamReader = New StreamReader(objStream)
Dim strHTML As String = objStreamReader.ReadToEnd

Response.Write(Server.HtmlEncode(strHTML))
Jan 24 '06 #1
4 1763
The body of an HTTP POST of form data is a set of URL-encoded name=value
pairs. For example, the body of the message you would want to send in this
case would be something like:

langpair=en%7Cde

Note the "%7C" used for the "|" character. For the most part, you can use
HttpUtility.UrlEncode to do the encoding of the string. However, many
servers don't recognize "%20" as a space, so you would want to use "+" for
spaces instead.

You just write the string to the stream you receive from the
GetResponseStream method.

The following example is in C#. I trust you can do the translation:

// ...code to initialize WebRequest and WebResponse...

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
System.IO.Stream requestStream = null;
byte[] body;

objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebbody = encoding.GetBytes("langpair=en%7Cde");
objWebRequest.ContentLength = body.Length;
requestStream = Request.GetRequestStream();
requestStream.Write(body, 0, body.Length);
objWebResponse = (HttpWebResponse)Request.GetResponse();

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Savas Ates" <in da club> wrote in message
news:u7**************@tk2msftngp13.phx.gbl...
I have a vb.net web application. I want to post some variables to another
web page and take some values back and process them.
This is codes in my target url. I should post "langpair" cariable to my
target url and it will respond with a value depend on a value which i
send.
<SELECT name=langpair><OPTION
value=en|de>English to German</OPTION><OPTION
value=en|es>English to Spanish</OPTION>
</select>

I must use post method. I must give a value for select object and post it
to
my target url ? I heard about BeginGetRequestStream but i dont know how
to
do it ?
Dim objURI As Uri = New Uri("http://www.isbuluyorum.com/translate")
Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
objWebRequest.ContentType = "text/html; charset=utf-8"
objWebRequest.Method = "POST"
'BEFORE to get response i should post variables to other web page ?
Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
Dim objStream As Stream = objWebResponse.GetResponseStream()
Dim objStreamReader As StreamReader = New StreamReader(objStream)
Dim strHTML As String = objStreamReader.ReadToEnd

Response.Write(Server.HtmlEncode(strHTML))

Jan 24 '06 #2
I wrote the code which is below. It seems ok but i have more variables to
send to my target web page ?
<textarea name=text1> </textarea>
<textarea name=text2> </textarea>

how can i add all variables to send to my target page ?


Dim encoding As New System.Text.ASCIIEncoding

Dim requestStream As System.IO.Stream

Dim objURI As Uri = New Uri(http://www.isbuluyorum.com)

Dim objWebRequest As WebRequest = WebRequest.Create(objURI)

objWebRequest.ContentType = "application/x-www-form-urlencoded"

objWebRequest.Method = "POST"

Dim body() As Byte

body = encoding.GetBytes("langpair=en%7Cde")

objWebRequest.ContentLength = body.Length

requestStream = objWebRequest.GetRequestStream

requestStream.Write(body, 0, body.Length)

Dim objWebResponse As WebResponse = objWebRequest.GetResponse()

Dim objStream As Stream = objWebResponse.GetResponseStream()

Dim objStreamReader As StreamReader = New StreamReader(objStream)

Dim strHTML As String = objStreamReader.ReadToEnd

Response.Write(strHTML)



"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:#W**************@TK2MSFTNGP09.phx.gbl...
The body of an HTTP POST of form data is a set of URL-encoded name=value
pairs. For example, the body of the message you would want to send in this
case would be something like:

langpair=en%7Cde

Note the "%7C" used for the "|" character. For the most part, you can use
HttpUtility.UrlEncode to do the encoding of the string. However, many
servers don't recognize "%20" as a space, so you would want to use "+" for
spaces instead.

You just write the string to the stream you receive from the
GetResponseStream method.

The following example is in C#. I trust you can do the translation:

// ...code to initialize WebRequest and WebResponse...

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
System.IO.Stream requestStream = null;
byte[] body;

objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebbody = encoding.GetBytes("langpair=en%7Cde");
objWebRequest.ContentLength = body.Length;
requestStream = Request.GetRequestStream();
requestStream.Write(body, 0, body.Length);
objWebResponse = (HttpWebResponse)Request.GetResponse();

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Savas Ates" <in da club> wrote in message
news:u7**************@tk2msftngp13.phx.gbl...
I have a vb.net web application. I want to post some variables to another
web page and take some values back and process them.
This is codes in my target url. I should post "langpair" cariable to my
target url and it will respond with a value depend on a value which i
send.
<SELECT name=langpair><OPTION
value=en|de>English to German</OPTION><OPTION
value=en|es>English to Spanish</OPTION>
</select>

I must use post method. I must give a value for select object and post it to
my target url ? I heard about BeginGetRequestStream but i dont know how
to
do it ?
Dim objURI As Uri = New Uri("http://www.isbuluyorum.com/translate")
Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
objWebRequest.ContentType = "text/html; charset=utf-8"
objWebRequest.Method = "POST"
'BEFORE to get response i should post variables to other web page ?

Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
Dim objStream As Stream = objWebResponse.GetResponseStream()
Dim objStreamReader As StreamReader = New StreamReader(objStream)
Dim strHTML As String = objStreamReader.ReadToEnd

Response.Write(Server.HtmlEncode(strHTML))


Jan 24 '06 #3
Ah yes. It works just like a QueryString. Each name=value pair is separated
by the "&" character, as in:

text1=blah+blah+blah&text2=blah+blah+blah

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Savas Ates" <in da club> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
I wrote the code which is below. It seems ok but i have more variables to
send to my target web page ?
<textarea name=text1> </textarea>
<textarea name=text2> </textarea>

how can i add all variables to send to my target page ?


Dim encoding As New System.Text.ASCIIEncoding

Dim requestStream As System.IO.Stream

Dim objURI As Uri = New Uri(http://www.isbuluyorum.com)

Dim objWebRequest As WebRequest = WebRequest.Create(objURI)

objWebRequest.ContentType = "application/x-www-form-urlencoded"

objWebRequest.Method = "POST"

Dim body() As Byte

body = encoding.GetBytes("langpair=en%7Cde")

objWebRequest.ContentLength = body.Length

requestStream = objWebRequest.GetRequestStream

requestStream.Write(body, 0, body.Length)

Dim objWebResponse As WebResponse = objWebRequest.GetResponse()

Dim objStream As Stream = objWebResponse.GetResponseStream()

Dim objStreamReader As StreamReader = New StreamReader(objStream)

Dim strHTML As String = objStreamReader.ReadToEnd

Response.Write(strHTML)



"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:#W**************@TK2MSFTNGP09.phx.gbl...
The body of an HTTP POST of form data is a set of URL-encoded name=value
pairs. For example, the body of the message you would want to send in
this
case would be something like:

langpair=en%7Cde

Note the "%7C" used for the "|" character. For the most part, you can use
HttpUtility.UrlEncode to do the encoding of the string. However, many
servers don't recognize "%20" as a space, so you would want to use "+"
for
spaces instead.

You just write the string to the stream you receive from the
GetResponseStream method.

The following example is in C#. I trust you can do the translation:

// ...code to initialize WebRequest and WebResponse...

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
System.IO.Stream requestStream = null;
byte[] body;

objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebbody = encoding.GetBytes("langpair=en%7Cde");
objWebRequest.ContentLength = body.Length;
requestStream = Request.GetRequestStream();
requestStream.Write(body, 0, body.Length);
objWebResponse = (HttpWebResponse)Request.GetResponse();

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Savas Ates" <in da club> wrote in message
news:u7**************@tk2msftngp13.phx.gbl...
>I have a vb.net web application. I want to post some variables to
>another
> web page and take some values back and process them.
>
>
> This is codes in my target url. I should post "langpair" cariable to
> my
> target url and it will respond with a value depend on a value which i
> send.
> <SELECT name=langpair><OPTION
> value=en|de>English to German</OPTION><OPTION
> value=en|es>English to Spanish</OPTION>
> </select>
>
>
>
> I must use post method. I must give a value for select object and post it > to
> my target url ? I heard about BeginGetRequestStream but i dont know
> how
> to
> do it ?
>
>
> Dim objURI As Uri = New Uri("http://www.isbuluyorum.com/translate")
> Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
> objWebRequest.ContentType = "text/html; charset=utf-8"
> objWebRequest.Method = "POST"
> 'BEFORE to get response i should post variables to other web
> page ? >
>
> Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
> Dim objStream As Stream = objWebResponse.GetResponseStream()
> Dim objStreamReader As StreamReader = New
> StreamReader(objStream)
> Dim strHTML As String = objStreamReader.ReadToEnd
>
> Response.Write(Server.HtmlEncode(strHTML))
>
>



Jan 24 '06 #4
thanks ;)
"Savas Ates" <in da club> wrote in message
news:u7**************@tk2msftngp13.phx.gbl...
I have a vb.net web application. I want to post some variables to another
web page and take some values back and process them.
This is codes in my target url. I should post "langpair" cariable to my
target url and it will respond with a value depend on a value which i send. <SELECT name=langpair><OPTION
value=en|de>English to German</OPTION><OPTION
value=en|es>English to Spanish</OPTION>
</select>

I must use post method. I must give a value for select object and post it to my target url ? I heard about BeginGetRequestStream but i dont know how to do it ?
Dim objURI As Uri = New Uri("http://www.isbuluyorum.com/translate")
Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
objWebRequest.ContentType = "text/html; charset=utf-8"
objWebRequest.Method = "POST"
'BEFORE to get response i should post variables to other web page ?

Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
Dim objStream As Stream = objWebResponse.GetResponseStream()
Dim objStreamReader As StreamReader = New StreamReader(objStream)
Dim strHTML As String = objStreamReader.ReadToEnd

Response.Write(Server.HtmlEncode(strHTML))

Jan 24 '06 #5

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

Similar topics

2
9682
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url);...
3
6329
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want...
8
2380
by: John K. | last post by:
Hi I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the...
12
2847
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts...
0
2189
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't...
4
1894
by: Savas Ates | last post by:
I have a vb.net web application. I want to post some variables to another web page and take some values back and process them. This is codes in my target url. I should post "langpair" cariable...
0
1339
by: thomasabcd | last post by:
Hi, During the user's registration I wan't to geo-code an address using localsearchmaps.com/geo. For that purpose I use a webrequest like this: string url =...
2
5953
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
1
8165
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
2
2949
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.