I have Solved :)
Searched many hours, tried many thinks and finally got it :)
If you have a parameter for get json data for example you have a weather apı and you need somewhere Weather.
This way explain How is sending String Request on API URL and Get Json data.
For Example my Request is,
{
"command":"read",
"ctrl":"summaryOfDay",
"data":{"date":"08.04.2016"},
"order":null,
"limit":null
}
I need This Info for my data.
After all that my code is Work.
private class downloadAPI extends AsyncTask<String,String,String>{
String dateStr;
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Akış Bilgileri Getiriliyor...");
pDialog.setIndeterminate(true);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
Date timeNow = new Date();
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
dateStr=df.format(timeNow)+"";
String data="{\"command\":\"read\",\"ctrl\":\"summaryOfDay\",\"data\":{\"date\":\""+dateStr+"\"},\"order\":null,\"limit\":null}";
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestMethod("POST");
connection.connect(); // it still works without this line, don't know why
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(data);
writer.close();
os.close();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine())!= null){
buffer.append(line);
}
String sJson = buffer.toString();
JSONObject mjson = new JSONObject(sJson);
return sJson;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if(connection != null) {
connection.disconnect();
}
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pDialog.dismiss();
mText.setText(result.toString());
}
}
Thanks everyone for helped me :)