问题
I'm trying to paste a string from my application to a website.
My application looks as following: one EditText and one Button. My button opens a website with an open text box.
<input name="FreeTextBox" type="text" id="FreeTextBox" style="width:64px;">
this is the text box on the website
My application's EditText id is et2
which is then the variable klass
in java.
klassen = klass.getText().toString();
The klass variable is then made into a string called klassen
When I click my button I open a website and then I want my application to automatically enter whatever I wrote in my EditText into the FreeTextBox on the website.
Please give me advice on how to do this. This is my first application so I could really use some help.
Thanks in advance
回答1:
Do you have control over the website? if not, then you are gonna need to get some more information, like the form action, and the input name, for example
<form name="input" action="html_form_action.php" >
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
If the form is like the one above I like using JSOUP (Download and import to your project)
Then I would use a code like this:
Jsoup.connect("http://****/html_form_action.php").data("user",yourTextString).post();
This code has the same effect as if you would have pasted the string in the website and then hit the Submit button. But again this might not be what you are looking for so please be more specific (Form source code and stuff)
回答2:
Use This Code
// Getting String from EditText
String url=editTextObj.getText().toString();
/// Declear Intent For open browser**/
Intent i = new Intent(Intent.ACTION_VIEW);
/// pass url which i want to send or get from edittext**/
i.setData(Uri.parse(url));
// fire intent
startActivity(i);
回答3:
I think you can add your text into a GET parameter or a POST parameter for your HTTP request.
If you choose the GET option (which is the less secure, but the easiest), you just have to do something like this :
String url = "http://www.mysite.com/myPage.php?parameter=value"
If you're using PHP, $_GET['parameter'] will be equal to "value" then you can set the field like you want with your PHP code.
Now, if you want to use the POST way, you'll have to take a look to the documentation. Actually, the answer of Rishabh is a great start.
(please do not forget to accept the answer that helps you ;-) )
来源:https://stackoverflow.com/questions/12449761/send-a-textstring-from-android-app-to-a-form-on-a-website