1
我不知道如何使用這個API來獲取一個index.html如何使用com.google.api.client.extensions.appengine.http.UrlFetchTransport獲得一個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);
}
}
我試過了但不起作用... – whisper 2013-05-14 05:00:11
@ user2354622你必須要更具體。請更新您的問題,以解釋什麼是不工作,錯誤信息是什麼,你寫的是什麼代碼導致的問題。 – 2013-05-14 14:29:51
HTTP錯誤500 訪問/ webrt時出現問題。原因: com/google/api/client/http/HttpTransport – whisper 2013-05-15 13:46:51