Android与IIS身份验证——基本验证_HttpClient Http请求 验证

来源:互联网 发布:centos 6.5搭建lnmp 编辑:程序博客网 时间:2024/05/18 18:03
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; }

0 0
原创粉丝点击