Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.administrator.a0502;
- import android.content.Context;
- import android.os.AsyncTask;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class LoginClass extends AsyncTask<Object, Object, String> {
- private final Context context;
- public LoginClass(Context c){
- this.context = c;
- }
- @Override
- protected String doInBackground(Object[] objects) {
- return posaljiZahtev();
- }
- protected void onPreExecute(){
- }
- @Override
- protected void onPostExecute(String result) {
- }
- public String posaljiZahtev()
- {
- String lokacijaServera = this.context.getString(R.string.lokacijaServera);
- try {
- URL url = new URL(lokacijaServera);
- HttpURLConnection connection = (HttpURLConnection)url.openConnection();
- connection.setRequestMethod("POST");
- connection.setRequestProperty("USER-AGENT", "Mozilla/5.0");
- connection.setRequestProperty("ACCEPT-LANGUAGE", "en-US,en;0.5");
- connection.setDoOutput(true);
- StringBuilder output = new StringBuilder();
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line = "";
- StringBuilder responseOutput = new StringBuilder();
- //System.out.println("output===============" + br);
- while((line = br.readLine()) != null ) {
- responseOutput.append(line);
- }
- br.close();
- //output.append(System.getProperty("line.separator") + "Response " + System.getProperty("line.separator") + System.getProperty("line.separator") + responseOutput.toString());
- output.append(responseOutput.toString());
- System.out.println("60.... " + output.toString());
- //return null;
- return output.toString();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement