Half of the code was not written by me (do not kick, I'm new to java, and even more so in android), but found from examples, as a result, it turned out (like) to make a request to the server, but here's the problem, I need a token, for that I need get a response from the server. It seems to be doing everything, like many, but that I was obviously wise.
Runnable runnable = new Runnable() { public void run() { HttpClient httpClient = new DefaultHttpClient(); // replace with your url HttpPost httpPost = new HttpPost("http://ololo.ru/login"); //Post Data List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2); nameValuePair.add(new BasicNameValuePair("login", "padavan")); nameValuePair.add(new BasicNameValuePair("password", "123123123")); //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); Log.d(TAG, response.toString()); } catch (IOException e) { e.printStackTrace(); } // write response to log } };
UPD: error, I realized that with this code, I hardly get an answer (the server sends the answer to json). Tell me how to remake the code.