1.下载"android-async-http-1.4.4.jar"的第三方JAR包,导入JAR包。
2.代码中用android-async-http网路请求。
void Save(){
try{
String url = this.getString(R.string.url) + "/api/MemberContacts/AddJobOffers";
String[] ary1 = {"userId","userPwd","PostName","JobType","Hiring","Payroll","Welfare","ExperienceYear","AcademicRequirements","PostEmail","PostPhone","JobDescription","Requirements"};
String[] ary2 = {
DESUtil.Decryption(SPUtil.getParam(this, "currentUserId", "").toString().trim()),
DESUtil.Decryption(SPUtil.getParam(this, "currentPassword", "").toString().trim()),
et_JobName.getText().toString().trim(),
tv_JobType.getText().toString().trim(),
et_NumberOfPeople.getText().toString().trim(),
tv_JobMoney.getText().toString().trim(),
tv_Welfare.getText().toString().trim(),
tv_JobTime.getText().toString().trim(),
tv_Education.getText().toString().trim(),
et_CompanyEmail.getText().toString().trim(),
et_CompanyPhone.getText().toString().trim(),
et_gwzz_add_job.getText().toString().trim(),
et_rzzz_add_job.getText().toString().trim() };
// 网络请求
// 创建异步请求端对象
AsyncHttpClient client = new AsyncHttpClient();
// 加密
String[] infoDES = new String[ary1.length];
for (int i = 0; i < ary1.length; i++) {
infoDES[i] = DESUtil.Encryption(ary2[i]).trim();
}
// 添加头参数
for (int i = 0; i < ary1.length; i++) {
client.addHeader(ary1[i], infoDES[i]);
}
// 执行post方法
client.post(url, null, new AsyncHttpResponseHandler() {
// 执行成功
@Override
public void onSuccess(int statusCode, Header[] headers,
byte[] responseBody) {
try {
// 解密
DESUtil.Decryption(new String(responseBody));
System.out.println("###: " + DESUtil.Decryption(new String(responseBody)));
} catch (Exception e) {
e.printStackTrace();
}
}
// 执行失败
@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
// 打印错误信息
error.printStackTrace();
toastText("网络请求出错");
}
});
} catch (Exception e) {
}
}