アンドロイドアプリからサーバーに名前と姓を送信しようとしています。しかし、接続を得ることができません。利用可能なコードのほとんどは使用していますが、いずれも作業していません。以下は私のコードのスナップショットです:アンドロイドアプリからサーバーへのHttpリクエスト
private void nextActivity(Profile profile) {
HttpURLConnection con = null;
try {
con = (HttpURLConnection)(new URL("**********/index.php")).openConnection();//not written the url for privacy concern
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
con.getOutputStream().write(("name=" + profile.getFirstName()).getBytes());
con.getOutputStream().write(("surname=" + profile.getLastName()).getBytes());
}
catch (ProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
if (profile != null) {
Intent main = new Intent(LoginActivity.this, MainActivity.class);
main.putExtra("name", profile.getFirstName());
main.putExtra("surname", profile.getLastName());
main.putExtra("imageUrl", profile.getProfilePictureUri(200, 200).toString());
startActivity(main);
}
}
}
私はあなたがここに...インターネット許可の –
チェックをAsyncTaskを使用している願っています&サーバー – VVB
あなたが例外を取得んpingを実行してみてください? –