curl命令移植android,将curl命令转换为Java / Android

HttpGet httpget = new HttpGet("url1");

client.getCookieStore().getCookies();

HttpResponse response1 = client.execute(httpget);

HttpEntity entity1 = response1.getEntity();

if (entity1 != null){

entity1.consumeContent();

}

if (cookies.isEmpty()) {

System.out.println("None");

} else {

for (int i = 0; i < cookies.size(); i++) {

System.out.println("- " + cookies.get(i).toString());

cookie = cookies.get(i);

}

}

} catch (ClientProtocolException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

try {

List nvps = new ArrayList();

nvps.add(new BasicNameValuePair("loginId", username.toString()));

nvps.add(new BasicNameValuePair("password", password.toString()));

nvps.add(new BasicNameValuePair("_eventId_submit", "Submit"));

HttpPost httppost = new HttpPost("url2");

httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

HttpParams params = httppost.getParams();

HttpConnectionParams.setConnectionTimeout(params, 45000);

HttpConnectionParams.setSoTimeout(params, 45000);

// Perform the HTTP POST request

HttpResponse response = client.execute(httppost);

status = response.getStatusLine().toString();

if (!status.contains("OK")) {

throw new HttpException(status);

}

if (cookies.isEmpty()) {

System.out.println("None");

} else {

for (int i = 0; i < cookies.size(); i++) {

System.out.println("- " + cookies.get(i).toString());

cookie = cookies.get(i);

}

}

} catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (HttpException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

List nvps2 = new ArrayList();

nvps2.add(new BasicNameValuePair("_eventId_submit", "Submit"));

HttpPost httppost2 = new HttpPost("url3");

httppost2.setEntity(new UrlEncodedFormEntity(nvps2, HTTP.UTF_8));

HttpParams params2 = httppost2.getParams();

HttpConnectionParams.setConnectionTimeout(params2, 45000);

HttpConnectionParams.setSoTimeout(params2, 45000);

// Perform the HTTP POST request

HttpResponse response2 = client.execute(httppost2);

if (cookies.isEmpty()) {

System.out.println("None");

} else {

for (int i = 0; i < cookies.size(); i++) {

System.out.println("- " + cookies.get(i).toString());

cookie = cookies.get(i);

settings.setASCookie(cookie);

}

}

} catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值