Actually I want to pass parameters in httpurlconnection get method. I am unable to do this as I am new in android. Can anyone please guide me how to send get request with parameters in android...please help me.
public AttemptSignIn(Context context) {
this.context = context;
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
try{
URL url = new URL("http://winktechs.com/windictor/sign_in.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
//conn.setDoOutput(true);
JSONObject jsonObj = new JSONObject();
jsonObj.put("email", email.getText().toString());
jsonObj.put("password", password.getText().toString());
JSONArray jsonArray = new JSONArray();
jsonArray.put(jsonObj);
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.connect();
int responseCode = conn.getResponseCode();
Log.d("response", responseCode + "");
if (responseCode==200) {
inputStream = new BufferedInputStream(conn.getInputStream());
String response = convertInputStreamToString(inputStream);
// parseResult(response);
result = 1; // Successful
flag = true;
}
else
{
flag = false;
}
}
catch (JSONException ej)
{
flag = false;
ej.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
if(flag==true)
{
Toast.makeText(context, "Logged In Successfully !", Toast.LENGTH_LONG).show();
Intent intent = new Intent(SignIn.this,MainActivity.class);
startActivity(intent);
finish();
}
else
{
//Toast.makeText(context, Res.toString(),Toast.LENGTH_LONG).show();
}
}
}
private String convertInputStreamToString(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null){
result += line;
}
/* Close Stream */
if(null!=inputStream){
inputStream.close();
}
return result;
}