【发布时间】:2017-04-15 12:42:05
【问题描述】:
我正在使用 AsyncTask 通过上传到 AWS 云中的 php 请求 json 数据。以下是我的代码:
@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();
...
我收到了这个错误:
java.net.UnknownHostException:无法解析主机“csci571.qiykuanrge.us-west-2.elasticbeanstalk.com”:没有与主机名关联的地址
我的 php 看起来像这样:
<?php
date_default_timezone_set('UTC');
header('Access-Control-Allow-Origin: *');
if (isset($_GET["key"])) {
if ($_GET["key"] == "leg") {
$url = "http://104.198.0.197:8080/legislators?order=state__asc,last_name__asc&per_page=all&apikey=";
$content = file_get_contents($url);
echo $content;
}
有人知道发生了什么吗?
【问题讨论】: