Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- button.setOnClickListener(new View.OnClickListener() {
- @RequiresApi(api = Build.VERSION_CODES.N)
- public void onClick(View v) {
- URL url= null;
- try {
- url = new URL("http://androidweb.azurewebsites.net/utilisateur/login");
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- HttpURLConnection connection=null;
- int responseCode=0;
- try {
- //JSONObject json=jsonParser.makeHttpRequest();
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("POST");
- TextView email=findViewById(R.id.email);
- TextView password=findViewById(R.id.password);
- connection.addRequestProperty("pseudo", email.getText().toString());
- connection.addRequestProperty("motDePasse", password.getText().toString());
- connection.setRequestProperty("Content-Type", "text/plain");
- connection.setRequestProperty("charset", "utf-8");
- connection.setConnectTimeout(10000); //Apres 10 sec renvoie un timeout
- connection.connect(); //Effectue la connection
- responseCode=connection.getResponseCode();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if(responseCode==200){
- try {
- InputStream stream = connection.getInputStream();
- BufferedReader rd = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
- JsonReader reader=new JsonReader(rd);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment