473,396 Members | 1,749 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,396 software developers and data experts.

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 1888
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
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
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...
12
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
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
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
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
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
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
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
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,...

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.