我正在研究概念验证,看看我是否可以解析X URL的响应。我得到一个JSON对象数组每当我在浏览器上点击这个URL时,每当我尝试使用下面的Java代码解析相同的URL时,我会得到一个空的JSON数组。我想知道这是否属于正常行为?它有什么解释吗?我使用正确的方法来获取数据吗?
{
"campaigns": [
]
};
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public class HTTPGetTest {
public static void main(String[] args) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://XXXX");
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httpGet);
String jSONString= EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("jSONString : "+ jSONString);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}