use of org.apache.http.client.ClientProtocolException in project SpiderForUESTC by ClaudiusGitHub.
the class Login method post.
/**
* post表单用来进行模拟登陆
*
* @param username
* @param password
*/
public void post(String username, String password) {
String url = "http://bbs.uestc.edu.cn/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=";
String[] hash = get().split(" ");
url = url + hash[0] + "&inajax=1";
HttpPost httpPost = new HttpPost(url);
//需要提交的表单数据
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("formhash", hash[1]));
formparams.add(new BasicNameValuePair("referer", "http://bbs.uestc.edu.cn/"));
formparams.add(new BasicNameValuePair("loginfield", "username"));
formparams.add(new BasicNameValuePair("username", username));
formparams.add(new BasicNameValuePair("password", password));
formparams.add(new BasicNameValuePair("questionid", "0"));
formparams.add(new BasicNameValuePair("answer", ""));
try {
UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
httpPost.setEntity(uefEntity);
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("--------------------------------------");
System.out.println("Response content: " + EntityUtils.toString(entity, "UTF-8"));
System.out.println("--------------------------------------");
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.http.client.ClientProtocolException in project HumaneApp by Ganesh1010.
the class Connectivity method makePostRequest.
public static HttpResponse makePostRequest(String uri, String json, HttpClient client, String token) {
try {
HttpPost httpPost = new HttpPost(uri);
httpPost.setEntity(new StringEntity(json));
if (token != null)
httpPost.setHeader("Authorization", "Token " + token);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
return client.execute(httpPost);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of org.apache.http.client.ClientProtocolException in project Activiti by Activiti.
the class SerializableVariablesDiabledTest method assertResponseStatus.
public void assertResponseStatus(HttpUriRequest request, int expectedStatusCode) {
CloseableHttpResponse response = null;
try {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("kermit", "kermit");
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
response = (CloseableHttpResponse) client.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
Assert.assertEquals(expectedStatusCode, statusCode);
if (client instanceof CloseableHttpClient) {
((CloseableHttpClient) client).close();
}
response.close();
} catch (ClientProtocolException e) {
Assert.fail(e.getMessage());
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
use of org.apache.http.client.ClientProtocolException in project Activiti by Activiti.
the class BaseJPARestTestCase method executeHttpRequest.
public HttpResponse executeHttpRequest(HttpUriRequest request, int expectedStatusCode) {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("kermit", "kermit");
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
try {
if (request.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
// Revert to default content-type
request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
}
HttpResponse response = client.execute(request);
Assert.assertNotNull(response.getStatusLine());
Assert.assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode());
return response;
} catch (ClientProtocolException e) {
Assert.fail(e.getMessage());
} catch (IOException e) {
Assert.fail(e.getMessage());
}
return null;
}
use of org.apache.http.client.ClientProtocolException in project Activiti by Activiti.
the class BaseJPARestTestCase method executeBinaryHttpRequest.
public HttpResponse executeBinaryHttpRequest(HttpUriRequest request, int expectedStatusCode) {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("kermit", "kermit");
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
try {
HttpResponse response = client.execute(request);
Assert.assertNotNull(response.getStatusLine());
Assert.assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode());
return response;
} catch (ClientProtocolException e) {
Assert.fail(e.getMessage());
} catch (IOException e) {
Assert.fail(e.getMessage());
}
return null;
}
Aggregations