Hashmap List. :
HashMap<String,String> contact=new HashMap<>();
contact.put("name",name);
contact.put("address",add);
try{
URL url=new URL(strURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(postDataStr(contact));
writer.flush();
writer.close();
os.close();
int responseCode=conn.getResponseCode();
conn.disconnect();
if (responseCode == HttpURLConnection.HTTP_OK)
return "success";
else
return "";
}catch (Exception e)
{
e.printStackTrace();
}
postDataStr() Hashmap , -, . :
private String postDataStr(HashMap<String, String> params) throws UnsupportedEncodingException{
StringBuilder result = new StringBuilder();
boolean first = true;
for(Map.Entry<String, String> entry : params.entrySet()){
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
}
return result.toString();
}