i am trying to post data via HTTP Post using name value key pair. But I am unable to post . The post url is http://mastercp.openweb.co.za/api/dbg_dump.asp .Should I include some header also while posting? Thanks
public class MainActivity extends Activity {
Button ok;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
ok=(Button)findViewById(R.id.but_signup_login);
ok.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
System.out.println("Clicked");
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://mastercp.openweb.co.za/api/dbg_dump.asp" });}});
}
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mastercp.openweb.co.za/api/dbg_dump.asp");
System.out.println("Clicked again");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(34);
String amount ="Ashish";
nameValuePairs.add(new BasicNameValuePair("User_Type", amount));
nameValuePairs.add(new BasicNameValuePair("User_Email", "ash@gmail.com"));
nameValuePairs.add(new BasicNameValuePair("User_Email_In", amount));
nameValuePairs.add(new BasicNameValuePair("User_Pass", amount));
nameValuePairs.add(new BasicNameValuePair("User_Mobile", amount));
nameValuePairs.add(new BasicNameValuePair("User_Mobile_In", amount));
nameValuePairs.add(new BasicNameValuePair("User_ADSL", amount));
nameValuePairs.add(new BasicNameValuePair("User_Org", amount));
nameValuePairs.add(new BasicNameValuePair("User_VAT", amount));
nameValuePairs.add(new BasicNameValuePair("User_Name", amount));
nameValuePairs.add(new BasicNameValuePair("User_Surname", amount));
nameValuePairs.add(new BasicNameValuePair("User_RegNo", amount));
nameValuePairs.add(new BasicNameValuePair("User_Address", amount));
nameValuePairs.add(new BasicNameValuePair("User_Town", amount));
nameValuePairs.add(new BasicNameValuePair("User_Code", amount));
nameValuePairs.add(new BasicNameValuePair("User_State", amount));
nameValuePairs.add(new BasicNameValuePair("User_Country", amount));
nameValuePairs.add(new BasicNameValuePair("User_ADSL", amount));
nameValuePairs.add(new BasicNameValuePair("User_ADSL_Address", amount));
nameValuePairs.add(new BasicNameValuePair("Payment_CC_Alt", amount));
nameValuePairs.add(new BasicNameValuePair("Payment_Type", amount));
nameValuePairs.add(new BasicNameValuePair("CProfile", amount));
nameValuePairs.add(new BasicNameValuePair("COrder", amount));
nameValuePairs.add(new BasicNameValuePair("Debit_Name", amount));
nameValuePairs.add(new BasicNameValuePair("Debit_Bank", amount));
nameValuePairs.add(new BasicNameValuePair("Debit_Number", amount));
nameValuePairs.add(new BasicNameValuePair("Debit_Code", amount));
nameValuePairs.add(new BasicNameValuePair("Debit_Type", amount));
nameValuePairs.add(new BasicNameValuePair("TOS_Agree", amount));
nameValuePairs.add(new BasicNameValuePair("Code", amount));
nameValuePairs.add(new BasicNameValuePair("package_activation", amount));
nameValuePairs.add(new BasicNameValuePair("session", amount));
nameValuePairs.add(new BasicNameValuePair("OnceOff", amount));
nameValuePairs.add(new BasicNameValuePair("submit-button", amount));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
System.out.println("Unsupported Exception "+e);
e.printStackTrace();
}
} catch (Exception e) {
System.out.println(" Exception last"+e);
// TODO Auto-generated catch block
}
}
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
for (String url : urls) {
postData();
}
return response;
}
@Override
protected void onPostExecute(String result) {}
}
}