I create projenct to android authentication with web services.I use post and json parsing to take data , I send to web servise username and pasword for authentication that take what I want to choose any infromation in pesponse data but whatever I did not successful to take what ı want to I think I make some mistake or forgot something.I want to login to web authentication and after authentication ,How take What I want to specific information.
class Post extends AsyncTask<Void, Void, Void>{
// Post tan önce yapılacak işlemler. Yükleniyor yazısını(ProgressDialog) gösterdik.
JSONObject veri_json;
JSONObject jsonobj;
protected void onPreExecute() {
pDialog=new ProgressDialog(OgrenciBilgiSistemi.this);
pDialog.setMessage("Yükleniyor");
pDialog.setIndeterminate(true);
pDialog.setCancelable(true);// ProgressDialog u iptal edilemez hale getirdik.
pDialog.show();
};
@Override
protected Void doInBackground(Void... unused) {// Arka Planda yapılacaklar. Yani Post işlemi
//Post edilecek değişkenleri ayarliyoruz.
List<NameValuePair> params=new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("login", og_no.getText().toString()));
params.add(new BasicNameValuePair("password", og_sifre.getText().toString()));
params.add(new BasicNameValuePair("Accept", "application/json"));
params.add(new BasicNameValuePair("Content-type", "application/json"));
//PostClass daki httpPost metodunu çağırdık.Gelen string değerini aldık
veri_string=post.httpPost(url, "POST", params, 2000);
try {
////gelen veri_string değerini json arraye çeviriyoruz.
//try içinde yapmak zorunlu çıkabilecek bir sorunda uygulamanın patlamaması için
veri_json=new JSONObject(veri_string);
} catch (JSONException e) {
e.printStackTrace();
}
// gelen veriyi log tuttuk
Log.d("HTTP POST CEVAP:",""+ veri_string);
return null;
}
And I have Post Class
try {
if (method == "POST") {
HttpParams httpParameters = new BasicHttpParams();
int timeout1 = time;
int timeout2 = time;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeout1);
HttpConnectionParams.setSoTimeout(httpParameters, timeout2);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
veri = httpEntity.getContent();
} else if (method == "GET") {
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
veri = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
veri, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
veri.close();
veri_string = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Hata " + e.toString());
}
return veri_string; // Aldığımız cevabın string halini geri dönüyoruz
}
I take this pesponse