私はAWSクラウドにアップロードされたphpを介してjsonデータを要求するためにAsyncTaskを使用しています。以下は私のコードです:Androidスタジオはphpにパラメータを渡してjsonからphpをリクエストします
にjava.net.UnknownHostException:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { new JsonTask().execute("http://XXX.qiykuanrge.us-west-2.elasticbeanstalk.com/index.php/?key=leg"); return leg_state_view; }
public class JsonTask extends AsyncTask<String, String, List<CongressModel>> {
@Override
protected List<CongressModel> doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
...
私はこのエラーましホストを解決できません「をcsci571.qiykuanrge.us- west2.elasticbeanstalk.com ":ホスト名に関連付けられたアドレスがありません
私のPHPは次のようになります:
<?php
\t date_default_timezone_set('UTC');
\t header('Access-Control-Allow-Origin: *');
\t if (isset($_GET["key"])) {
\t \t if ($_GET["key"] == "leg") {
\t \t \t $url = "http://104.198.0.197:8080/legislators?order=state__asc,last_name__asc&per_page=all&apikey=";
\t \t \t $content = file_get_contents($url);
\t \t \t echo $content;
\t \t }
誰かが何が起こっているか知っていますか?
をエンコードリンクはhttp://csci571.qiykuanrge.us-west-2.elasticbeanstalk.com/index.php/?key = legでなければなりません。私は間違って投稿し、私は今それを編集します。エラーは残ります.. – DawnZHANG
@DollyAswinが述べているように、電話のブラウザからそのリンクにアクセスしようとするとどうなりますか?あなたはどんな反応を得ますか? – gian1200
私は新しいURL http://csci571.qiykuanrge.us-west-2.elasticbeanstalk.com/index.php/?key=legにアクセスしており、jsonは身体の反応として与えています。つまり、PHPに問題はありません。 Androidでインターネットに接続できないために発生した問題 –