Уже 4 дня голову ломаю, ниже код свой покажу:
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
/**
* Created by andrej on 23.08.15.
*/
public class PostTask extends AsyncTask {
public String str;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
try {
BufferedReader reader = null;
URL url = new URL("
192.168.1.3:8888/1/login.php");
HttpsURLConnection conct = (HttpsURLConnection) url.openConnection();
conct.setReadTimeout(10000);
conct.setRequestMethod("POST");
conct.setConnectTimeout(15000);
conct.setRequestProperty("Accept-Charset", "UTF-8");
conct.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
conct.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
conct.setDoInput(true);
conct.setDoOutput(true);
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("login", "andrey")
.appendQueryParameter("password", "123456");
String query = builder.build().getEncodedQuery();
Log.e("Данные на сервер", query);
DataOutputStream wr = new DataOutputStream(conct.getOutputStream());
wr.writeBytes(query);
wr.flush();
wr.close();
conct.connect();
reader= new BufferedReader(new InputStreamReader(conct.getInputStream()));
StringBuilder buf = new StringBuilder();
String line = null;
while ((line=reader.readLine()) != null) {
buf.append(line + "\n");
}
str = (buf.toString());
Log.e("Данные на сервер", str);
}
catch (Exception e){
Log.e("Ошибка в асинк таск", "ДуинБэкграунд");
return null;
}
return null;
}
@Override
protected void onPostExecute(Void Void) {
super.onPostExecute(Void);
//Log.e("Результат выполнения",str);
}
}