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