Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm writing a bot that will have the option to filter messages through this website, http://www.gizoogle.net/textilizer.php .
I want to send the string via post and have it send back the translation. Looking on the site through my browser console, I see the text is translatetext and the name of the box that it's in is called textarea. I've never actually done this before and have absolutely no idea how to go about it or where to start. Any advice would be immensely helpful! This will be coded in Visual Basic but I also know C#.
Posted

1 solution

Try this:
Dim text As string = "The following procedure describes the steps used to send data to a server. This procedure is commonly used to post data to a Web page."
 
Dim result As String = ""
Dim myrequest As HttpWebRequest = HttpWebRequest.Create("http://www.gizoogle.net/textilizer.php")
myrequest.Method = "POST"
myrequest.Timeout = 1000
myrequest.ContentType = "application/x-www-form-urlencoded"
 
Dim bytedata As byte() =  Encoding.UTF8.GetBytes("translatetext="& text &"translate=Tranzizzle+Dis+Shiznit")
myrequest.ContentLength = bytedata.Length
 
Dim requestStream As Stream = myrequest.GetRequestStream()
requestStream.Write(bytedata, 0, bytedata.Length)
requestStream.Close()
 
Try
   Dim resp As System.Net.HttpWebResponse = myrequest.GetResponse()
 
   Dim sr As New System.IO.StreamReader(resp.GetResponseStream())
   result = sr.ReadToEnd()
   sr.Close()
 
   Dim re As RegEx = new RegEx("<textarea.*?name=""translatetext"".*?>(.*?)</textarea>")
   Dim m As Match = re.Match(result)
   
   If m.Success
   		result = m.groups(1).Value
   End If
 
   Console.WriteLine(result)
Catch ex As WebException
   If ex.Status = WebExceptionStatus.Timeout Then
       result = "Error: The request has timed out"
   Else
       result = "Error: " + ex.Message
   End If
End Try
 
Share this answer
 
v2
Comments
TokyoScarab 11-Oct-15 13:46pm    
I tried the code above and the response I got back was
"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
"
Zoltán Zörgő 11-Oct-15 14:42pm    
1) If you look carefully, the result variable will hold all the http response body. You will need to extract the portion you need:
<textarea type="text" name="translatetext" style="width: 600px; height:250px;"/>Da followin procedure raps bout tha steps used ta bust data ta a server n' sh*t. This procedure is commonly used ta post data ta a Web page.translate=Tranzizzle Dis Shiznit</textarea>
If you don't want to parse the DOM, you can simply use RegExp for that. See updated answer.
TokyoScarab 11-Oct-15 16:58pm    
Thanks! I had to modify a couple changes in the code because Current VB didn't like the syntax of a few thing you mentioned, but I got it to work! One thing I couldn't fix was the timeout check. I get an error for "ex.Status" saying that 'status' is not a member of System.Exception. I won't really need a check for that though. Thanks though for all the help! It will make doing this in the future a lot easier :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900