サーバーにデータを投稿する場合は、投稿データのサーバーを適切に設計する必要があります。最近私のサーバー構成私はこのコードを使用してデータを投稿し、よく実行されます。
Button send = (Button) findViewById(R.id.send_sms);
send.setOnClickListener(this);
public void onClick(View v)
{
switch (v.getId())
{
case R.id.send_sms:
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://10.0.2.2/folder/saver.php";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cell", "+8801899999"));
params.add(new BasicNameValuePair("pin", "1234"));
params.add(new BasicNameValuePair("msg", "hi!"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
showAlert(EntityUtils.toString(resEntity));
//Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
私はAndroidに新しいです! –
Androidを初めてお使いの場合は、最初にいくつかのことを読む必要があります。 http://developer.android.com/reference/android/os/AsyncTask.html これがあなたに明確になることを願っています。 –
どうすればAsyncTaskで正しく行うためのコードを更新できますか? –