コーディングにはまだ新しいが、これまでかなりの成果を収めている。このコード行で作成したアプリケーションからウェブサイトにエコーを送ることができる。Eclipseで入力した情報を送信する方法
String url = "http://beatswith.us/mtest.php?username=";
=後
ものは...私が把握カントは何のURLに編集テキストフィールドに入力いただきまし送信する方法を、これまで
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Loginretrieve extends Activity {
EditText getInput;
TextView textOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.logpage);
getInput = (EditText) findViewById(R.id.username);
String url = "http://beatswith.us/mtest.php?username=";
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response1;
try {
response1 = httpClient.execute(httpGet);
Object responseString = getResponseString(response1);
TextView textView = (TextView)findViewById(R.id.textView1);
textView.setText(responseString.toString());
} catch (ClientProtocolException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
public static String getResponseString(HttpResponse response)
throws IllegalStateException, IOException {
String responseString = "";
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
Log.d("beats.us.with", "Output");
}
in.close();
responseString = sb.toString();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return responseString;
}
}
httpclientチュートリアルを見ましたか?彼らはフォームを記入して提出する様々な方法について議論します。 –