public String postURL(ArrayList<NameValuePair> nameValue, String url) {
InputStream is = null;
String line = "";
String sb = "";
DefaultHttpClient client = new DefaultHttpClient();
CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT), new UsernamePasswordCredentials("username","pwd"));
client.setCredentialsProvider(credProvider);
HttpPost post = new HttpPost(url);
try {
post.setEntity(new UrlEncodedFormEntity(nameValue, HTTP.UTF_8));
HttpConnectionParams.setConnectionTimeout(client.getParams(),
8 * 1000);
HttpConnectionParams.setSoTimeout(client.getParams(), 8 * 1000);
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, HTTP.UTF_8));
while ((line = reader.readLine()) != null) {
sb += line;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb;
}
Android与IIS身份验证——基本验证_HttpClient Http请求 验证
最新推荐文章于 2023-05-17 19:49:16 发布
