我正在尝试将http请求POST发送到我的goolge表单以更新我的工作表,但在Android Studio中出现此错误:
线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / commons / logging / LogFactory 在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) {}
}
}
请帮助我!