Ich muss einige Daten per POST senden, was bedeutet das? Ich starte meine Android-App, fülle einige Textfelder mit Daten aus und klicke auf die Schaltfläche. Durch Klicken auf diese Schaltfläche muss ich den WebBrowser öffnen und Daten an diese Website senden ...
Hier ist mein Code, an den ich POST sende:
Code: Select all
/****** SEND POST REQUEST ******/
private void sendPostRequest_cabinet(String clientID)
{
class SendPostReqAsyncTask extends AsyncTask
{
@Override
protected String doInBackground(String... params)
{
// insert data into massive
String paramClientID = params[0];
HttpClient httpClient = new DefaultHttpClient();
//httpPost = new HttpPost(post_url + /*language from dropdown + */ "/en/login/");
if (LANGUAGE != null)
{
if (LANGUAGE.equals("English"))
{
httpPost = new HttpPost(link.getEng());
Toast.makeText(getApplicationContext(), (CharSequence) httpPost, Toast.LENGTH_LONG).show();
}
else if (LANGUAGE.equals("Russian"))
{
httpPost = new HttpPost(link.getRussian());
}
else if (LANGUAGE.equals("Dutch(German)"))
{
httpPost = new HttpPost(link.getDeutch());
}
else if (LANGUAGE.equals("French"))
{
httpPost = new HttpPost(link.getFrance());
}
else if (LANGUAGE.equals("Italian"))
{
httpPost = new HttpPost(link.getItalian());
}
else if (LANGUAGE.equals("Spanish"))
{
httpPost = new HttpPost(link.getSpanish());
}
}
// send parameters with values
BasicNameValuePair email1BasicNameValuePair = new BasicNameValuePair("client_id", paramClientID);
// insert parameters into massive
List nameValuePairList = new ArrayList();
nameValuePairList.add(email1BasicNameValuePair);
try
{
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairList);
httpPost.setEntity(urlEncodedFormEntity);
try
{
HttpResponse httpResponse = httpClient.execute(httpPost);
InputStream inputStream = httpResponse.getEntity().getContent();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader buffereReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String bufferedStrChunk = null;
while ((bufferedStrChunk = buffereReader.readLine()) != null)
{
stringBuilder.append(bufferedStrChunk);
}
return stringBuilder.toString();
}
catch (ClientProtocolException cpe)
{
System.out.println("First Exception of HttpResponse: " + cpe);
cpe.printStackTrace();
}
catch (IOException ioe)
{
System.out.println("Second Exception of HttpResponse: " + ioe);
ioe.printStackTrace();
}
}
catch (UnsupportedEncodingException uee)
{
System.out.println("An Exception given because of UrlEncodedFormEntity argument : " + uee);
uee.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result)
{
// Toast.makeText(getApplicationContext(),
// "POST request has been send successfully",
// Toast.LENGTH_LONG).show();
super.onPostExecute(result);
//Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
//go to the browser with lang redirect
if (LANGUAGE != null)
{
if (LANGUAGE.equals("English"))
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(link.getEng()));
startActivity(i);
}
else if (LANGUAGE.equals("Russian"))
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(link.getRussian()));
startActivity(i);
}
else if (LANGUAGE.equals("Dutch(German)"))
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(link.getDeutch()));
startActivity(i);
}
else if (LANGUAGE.equals("French"))
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(link.getFrance()));
startActivity(i);
}
else if (LANGUAGE.equals("Italian"))
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(link.getItalian()));
startActivity(i);
}
else if (LANGUAGE.equals("Spanish"))
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(link.getSpanish()));
startActivity(i);
}
}
}
}
/***** second check of Internet connection *****/
if (!isOnline())
{
showNoConnectionDialog(this);
// Toast.makeText(getApplicationContext(),
// "Internet connection is disabled!", Toast.LENGTH_LONG).show();
}
else
{
SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
sendPostReqAsyncTask.execute(clientID);
}
}
So sende ich Daten und erhalte Daten aus früheren Aktivitäten:
Code: Select all
//go to the ThirdScreen
Intent intent = new Intent(SecondScreen.this, ThirdScreen.class);
intent.putExtra("CLIENT_ID", stringClientID);
intent.putExtra("PASSWORD", getUserPWD);
intent.putExtra("LANGUAGE", language);
startActivity(intent);
finish();
Intent intent = getIntent();
CLIENT_ID = intent.getExtras().getString("CLIENT_ID");
Mobile version