我对java很新.... 对于一个大学项目,我正在开发一个带有Java(Java EE)的网站,在那个网站上,我需要一些用php制作的网站的信息,其API可供使用.... 让我让自己更清楚
我的网站A(WITH JAVA)需要网站B的一些信息(WITH PHP,API可用).... 那我怎么能得到这些信息........
我猜ajax请求只能从客户端进行,我想在服务器端这样做,我该怎么做才能帮助我......
答案 0 :(得分:1)
例如,您希望运行带有java的get,您可以使用它:
import org.apache.http.HttpEntity;
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.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
HttpClient client = HttpClientBuilder.create().build();
HttpGet requestGet = new HttpGet(url + params);
HttpResponse response = client.execute(requestGet);
HttpEntity entity = response.getEntity();
responseString = EntityUtils.toString(entity, "UTF-8");
答案 1 :(得分:0)
HttpClient client = HttpClientBuilder.create().build();
HttpGet requestGet = new HttpGet(url + params);
HttpResponse response = client.execute(requestGet);
HttpEntity entity = response.getEntity();
responseString = EntityUtils.toString(entity, "UTF-8");
使用这些行来调用api。 这里url是api的链接,params是必需的参数。