我不知道如何使用这个 API 来获取 index.html
请给我一个样品。
这是我的完整代码,HTTP 错误 500
package com.webrt;
import java.io.IOException;
import javax.servlet.http.*;
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
@SuppressWarnings("serial")
public class WebRTServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
UrlFetchTransport HTTP_TRANSPORT = new UrlFetchTransport();
HttpRequestFactory httprequestFactory = HTTP_TRANSPORT
.createRequestFactory();
GenericUrl url = new GenericUrl("http://www.google.com");
HttpRequest request = httprequestFactory.buildGetRequest(url);
String index = request.execute().parseAsString();
System.out.println(index);
}
}