package com.example.httprequestexample; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class HTTPPostActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); makePostRequest(); } private void makePostRequest() { HttpClient httpClient = new DefaultHttpClient(); // replace with your url HttpPost httpPost = new HttpPost("http://sms321.ir/webservice/rest/sms_send?"); //Post Data List nameValuePair = new ArrayList(2); nameValuePair.add(new BasicNameValuePair("login_username", "USERNAME")); nameValuePair.add(new BasicNameValuePair("login_password", "PASSWORD")); nameValuePair.add(new BasicNameValuePair("receiver_number", "09132677411")); nameValuePair.add(new BasicNameValuePair("note_arr[]", "سلام")); nameValuePair.add(new BasicNameValuePair("sender_number", "10007666")); //Encoding POST data try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair)); } catch (UnsupportedEncodingException e) { // log exception e.printStackTrace(); } //making POST request. try { HttpResponse response = httpClient.execute(httpPost); // write response to log Log.d("Http Post Response:", response.toString()); } catch (ClientProtocolException e) { // Log exception e.printStackTrace(); } catch (IOException e) { // Log exception e.printStackTrace(); } } }