メールを送るインターフェースの経験のまとめを呼び出します。

2611 ワード

ショートメッセージのインターフェイスはHTTPプロトコルに基づいて呼び出しを要求しています。元々はPost、Getの要求方式にしか接触していません。Putの要求を使ったことがありません。
1、要求方式PUT---httpclient-4.2.5.jarとhttp coree-42.2.4.jarに使用して、参考http://download.csdn.net/download/hellosoftware/8744277
要求ヘッダの具体的な意味は、参照することができる。http://tools.jb51.net/table/http_header
public String sendPUT(String restfulUrl, Map params) {
		HttpClient client = new DefaultHttpClient();
		HttpPut requestPut = new HttpPut(restfulUrl);
		//     ,           
		requestPut.setHeader("Accept","application/json, application/xml, text/html, text/*, image/*, */*");
		final List putData = new ArrayList();
		for (Map.Entry entry : params.entrySet()) {
			putData.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		if (params != null && !params.isEmpty()) {
			try {
				UrlEncodedFormEntity entity = new UrlEncodedFormEntity(putData,
						HTTP.UTF_8);
				requestPut.setEntity(entity);
			} catch (UnsupportedEncodingException ignore) {
				ignore.printStackTrace();
			}
		}
		String result = "";
		try {
			HttpResponse httpResponse = client.execute(requestPut);
			if (httpResponse == null)
				return result;
			if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
				result = EntityUtils.toString(httpResponse.getEntity());
		} catch (IOException ignore) {
			ignore.printStackTrace();
			if (LOG.isErrorEnabled())
				LOG.error(ignore);
		} finally {
			if (client != null)
				client.getConnectionManager().shutdown();
		}
		return result.toString();
}
2、MD 5暗号化の参考:http://blog.csdn.net/miaoyahong/article/details/50561881
public class MD 5 Util{             public static void main(String[]args){          String pwd=getMD 5(「password」);          System.out.println(pwd)      }          //生成MD 5      public static String getMD 5(String message){          String md 5="          try{              Message Digest md=Message Digest.get Instance(“MD 5”); // md 5アルゴリズムオブジェクトを作成します。              byte[]messageByte=message.getByttes(「UTF-8」)              byte[]md 5 Byte=md.digest;             // MD 5バイト配列、16*8=128ビットを取得します。              md 5=bytes ToHex(md 5 Byte)                           // 16進数文字列に変換          } catch(Exception e){              e.print StockTrace();          }           return md 5      }            // バイナリ変換16進数      public static String bytes ToHex(byte[]bytes){          StringBuffer hexStr=new StringBuffer()          int num          for(int i=0;i