0
我試圖發送http請求POST到我的goolge表單來更新我的工作表,但是有這個錯誤Android的工作室:java.lang.NoClassDefFoundError org/apache/commons/logging/LogFactory at org.apache.http.conn.ssl
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.http.conn.ssl
在這一行:CloseableHttpClient httpClient = HttpClientBuilder.create().build();
但在Eclipse中它的作品!
我的代碼是:
public class MyClass{
public static void main(String[] args)
throws IOException, ServiceException
{
String fullUrl = "https://docs.google.com/forms/d/**key**/formResponse";
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(fullUrl);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpResponse response = null;
String data = "entry_770028073=" + URLEncoder.encode("ITPOD_pp1")+"&"+"entry_835458425=" + URLEncoder.encode("sr1");
StringEntity tmp = new StringEntity(data,"UTF-8");
httpPost.setEntity(tmp);
try {
response = httpClient.execute(httpPost,localContext);
if (response != null) {
String res = EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {}
}
}
請幫幫我!
如果Android Studio中想支持老HTTP客戶端,在gradle這個機器人{ useLibrary「組織添加這些行.apache.http.legacy' },我沒有多少工作,但這是android開發人員網站給出的。 – dex