//Here is what i have tried. // I don't know how to append inputurl and Content values and send this to server using HttpURLConnection.
public JSONObject getJsonFromUrl(String inputurl, ContentValues values) {
// Making http Request
try {
URL url=new URL(inputurl);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setReadTimeout(10000 /* milliseconds */);
connection.setConnectTimeout(15000 /* milliseconds */);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
/// please insert the code here for appending values with url. connection.connect();
//
inputStream=connection.getInputStream();
}
catch (java.net.MalformedURLException e1){
e1.printStackTrace();
}
catch (UnsupportedEncodingException e2) {
e2.printStackTrace();
}
try {
BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"),8);
reader.read(getPost)
StringBuilder builder=new StringBuilder();
String line=null;
while ((line=reader.readLine() !=null){
builder.append(line + "n");
}
inputStream.close();
jsonString=inputStream.toString();
Log.e("JSON", jsonString);
}
catch (Exception e){
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try to parse the string into json object
try {
jsonObject=new JSONObject(jsonString);
}
catch (JSONException e){
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jsonObject;
}
}
if you want to post a JSON object to an url though HttpUrlConnection instance you can write is like this.
the entire code may look like this