I have simple HTML.
<html>
<body>
<form action=http://google.com method=get>
<input type=text name=q>
<input type=submit>
</form>
</body>
</html>
How to make xojo web app to same as above?
I make as below, but cause error in NextSocket.SetFormData(d) as Exception as NilObjectException.
Sub Action()
Var d As New Dictionary
d.Value("q") = TextField1.text
NextSocket.SetFormData(d)
NextSocket.Post("http://www.google.com")
End Sub
That would seem to suggest that NextSocket has not been created yet. What does your code look like to instantiate that object?
NextSocket = new URLConnection
Thank you Anthony!
I already added property “NextSocket” as HTTPSocket at “Webpage1”.
So, I modify as :
Var d As New Dictionary
d.Value("q") = TextField1.text
NextSocket = new URLConnection
NextSocket.SetFormData(d)
NextSocket.Post("http://www.google.com")
but, Type mismatch error at line of “NextSocket = new URLConnection”
So, I delete property “NextSocket” from “Webpage1”, but error “This item does not exist” at line of"NextSocket = new URLConnection"
any help?
If you’re using HTTPSocket, then the instantiation line should be this:
NextSocket = new HTTPSocket
Anthony, Thank you again!
I restore property “NextSocket” as “HTTPSocket” from "Webpage1.
and I change as below at Button1:
Var d As New Dictionary
d.Value("q") = TextField1.text
NextSocket = new HTTPSocket
NextSocket.SetFormData(d)
NextSocket.Post("http://www.google.com")
All errors is clear.
But, when I push Button1, cause nothing.
One more breath!
If you’re trying to retrieve and parse search results, then you’ll have to implement the PageReceived event.
Add a method like this:
Private Sub handler_PageReceived(sender as HTTPSocket, url as String, httpStatue as Integer, headers as InternetHeaders, content as String)
'// Do something with content here.
End Sub
Then, after the line to instantiate NextSocket:
AddHandler NextSocket.PageReceived, AddressOf handler_PageReceived
Hi! Thank you Anthony!
I don’t want parsing results, I just want a page move to an arbitrary URL with POST or GET form data.
In my last experiment, pressing Button1 did not turn the web page.
What can I do for such a purpose?
I don’t understand what you mean by “turn the web page”. If you just want to submit data, then what are you expecting to happen in Xojo?
I think this is what you’re after.
I believe he wants to set the .value of an input element in an external website. I’m a bit lost
Thank you Anthnony!
I write as:
Me.ShowURL("http://www.google.com")
It is work without form value. But,
Var d As New Dictionary
d.Value("q") = TextField1.text
Me.ShowURL.SetFormData(d)
Me.ShowURL("http://www.google.com")
Xojo sais:
Not enough arguments: got 0, expected at least 1.
Me.ShowURL.SetFormData(d)
Hello Hector!
I believe he wants to set the .value of an input element in an external website. I’m a bit lost
Yes. I want to set the value of an input element.
That won’t work. You’ll need to use URL parameters as the HTTPSocket isn’t going to help with what you want to do. For Google, you can read up on these here.
I make code as below:
[code]
dim NextSocket as new HTTPSocket
dim d as new Dictionary
d.value(“q”) = TextField1.text
NextSocket.SetFormData(d)
Var result As String
result = NextSocket.Get(“http://www.google.com”, 30)
result = DefineEncoding(result, Encodings.UTF8)
MessageBox(result)[/code]
It is run without NilObjectException.
Certainly the HTTPSocket + SetFormData didn’t help for Google.
I make URL praramater instead SetFormData as :
dim NextSocket as new HTTPSocket
var d as string
var URLstring as string
URLString = "http://www.google.com/search?q="+ TextField1.text
Var resultdata1 As String
resultdata1 = NextSocket.Get(URLString, 30)
But…
This is not what I want to do.
We do not want to put the results of the HTTP request to resultdata1 variable, but want to display a URLString to the web browser.
How can we make this happen?
I find simple solution as:
Me.ShowURL("http://www.google.com/search?q="+TextField1.text)
Thank you.