package com.example.patrice.http01;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import org.json.JSONObject;

import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Patrice on 19/12/2017.
 */

// https://www.studytutorial.in/android-httpurlconnection-post-and-get-request-tutorial

public class http06 extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.http06_layout);

        new SendPostRequest().execute();
        //URL url = new URL("https://studytutorial.in/post.php");
        //URL url = new URL("http://analog-design.net/WORKAREA/WEBSITE/Codebar/http06.php");

    }


    public class SendPostRequest extends AsyncTask<String, Void, String> {

        protected void onPreExecute(){}

        protected String doInBackground(String... arg0)
        {

            try{

                URL url = new URL("http://analog-design.net/WORKAREA/WEBSITE/Codebar/http06.php");

                JSONObject postDataParams = new JSONObject();
                postDataParams.put("name", "abc");
                postDataParams.put("email", "abc@gmail.com");
                Log.e("params",postDataParams.toString());

                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setReadTimeout(15000 /* milliseconds */);
                conn.setConnectTimeout(15000 /* milliseconds */);
                conn.setRequestMethod("POST");
                conn.setDoInput(true);
                conn.setDoOutput(true);
            }
            catch(Exception e){
                return new String("Exception: " + e.getMessage());
            }

            return("");
        }

        @Override
        protected void onPostExecute(String result) {}
    }




}

