2023年7月31日发(作者:)
调⽤发送短信接⼝经验总结短信接⼝要求基于HTTP协议调⽤,原来只接触过Post、Get请求⽅式,没有⽤过Put请求。public String sendPUT(String restfulUrl, Map params) { HttpClient client = new DefaultHttpClient(); HttpPut requestPut = new HttpPut(restfulUrl); //设置请求头,根据接⼝规范做相应调整 der("Accept","application/json, application/xml, text/html, text/*, image/*, */*"); final List putData = new ArrayList(); for ( entry : et()) { (new BasicNameValuePair((), ue())); } if (params != null && !y()) { try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(putData, _8); ity(entity); } catch (UnsupportedEncodingException ignore) { tackTrace(); } } String result = ""; try { HttpResponse httpResponse = e(requestPut); if (httpResponse == null) return result; if (tusLine().getStatusCode() == _OK) result = ng(ity()); } catch (IOException ignore) { tackTrace(); if (rEnabled()) (ignore); } finally { if (client != null) nectionManager().shutdown(); } return ng();}public class MD5Util {
public static void main(String[] args) {
String pwd = getMD5("password");
n(pwd);
}
//⽣成MD5
public static String getMD5(String message) {
String md5 = "";
try {
MessageDigest md = tance("MD5"); // 创建⼀个md5算法对象
byte[] messageByte = es("UTF-8");
byte[] md5Byte = (messageByte); // 获得MD5字节数组,16*8=128位
md5 = bytesToHex(md5Byte); // 转换为16进制字符串
} catch (Exception e) {
tackTrace();
}
return md5;
}
// ⼆进制转⼗六进制
public static String bytesToHex(byte[] bytes) {
StringBuffer hexStr = new StringBuffer();
int num;
for (int i = 0; i < ; i++) {
num = bytes[i];
if(num < 0) {
num += 256;
}
if(num < 16){
("0");
}
(tring(num));
}
return ng();
}
}
2023年7月31日发(作者:)
调⽤发送短信接⼝经验总结短信接⼝要求基于HTTP协议调⽤,原来只接触过Post、Get请求⽅式,没有⽤过Put请求。public String sendPUT(String restfulUrl, Map params) { HttpClient client = new DefaultHttpClient(); HttpPut requestPut = new HttpPut(restfulUrl); //设置请求头,根据接⼝规范做相应调整 der("Accept","application/json, application/xml, text/html, text/*, image/*, */*"); final List putData = new ArrayList(); for ( entry : et()) { (new BasicNameValuePair((), ue())); } if (params != null && !y()) { try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(putData, _8); ity(entity); } catch (UnsupportedEncodingException ignore) { tackTrace(); } } String result = ""; try { HttpResponse httpResponse = e(requestPut); if (httpResponse == null) return result; if (tusLine().getStatusCode() == _OK) result = ng(ity()); } catch (IOException ignore) { tackTrace(); if (rEnabled()) (ignore); } finally { if (client != null) nectionManager().shutdown(); } return ng();}public class MD5Util {
public static void main(String[] args) {
String pwd = getMD5("password");
n(pwd);
}
//⽣成MD5
public static String getMD5(String message) {
String md5 = "";
try {
MessageDigest md = tance("MD5"); // 创建⼀个md5算法对象
byte[] messageByte = es("UTF-8");
byte[] md5Byte = (messageByte); // 获得MD5字节数组,16*8=128位
md5 = bytesToHex(md5Byte); // 转换为16进制字符串
} catch (Exception e) {
tackTrace();
}
return md5;
}
// ⼆进制转⼗六进制
public static String bytesToHex(byte[] bytes) {
StringBuffer hexStr = new StringBuffer();
int num;
for (int i = 0; i < ; i++) {
num = bytes[i];
if(num < 0) {
num += 256;
}
if(num < 16){
("0");
}
(tring(num));
}
return ng();
}
}
发布评论