java接口同步

public class SendRemoteResult {
 //public static String path="http://localhost:68/jforum/forums/synUser.page";
 public static String path="http://192.168.0.74/forums/synUser.page";
 public String sendResult(Integer userId,String userName,String password,String email,Integer addtime){
  String key="userId="+userId+"&userName="+userName+"&password="+password+"&email="+email+"&addtime="+addtime;
  StringBuilder nameValue = new StringBuilder();
  nameValue.append("userId="+userId+"&userName="+userName+"&password="+password+"&email="+email+"&addtime="+addtime+"&basekey="+encodeStr(key));
  return getResultFromRemote("url="+encodeStr(nameValue.toString()));
 }
 private String getResultFromRemote(String nameValue){
  try{
   URL url = new URL(path);
   HttpURLConnection connection = (HttpURLConnection) url.openConnection();
   connection.setDoOutput(true);
   connection.setDoInput(true);
   connection.setRequestMethod("POST");
   connection.setReadTimeout(600000);
   BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
   bos.write(nameValue.getBytes("UTF-8"));
   bos.close();
   InputStream is = connection.getInputStream();
   InputStreamReader in = new InputStreamReader(is, "UTF-8");
   BufferedReader br = new BufferedReader(in);
   String str = null;
   StringBuffer sb = new StringBuffer();
   while ((str = br.readLine()) != null){
    sb.append(str);
    sb.append("\n");
   }
   br.close();
   return sb.toString();
  }catch (Exception e) {
   e.printStackTrace();
   return null;
  }
 }
 
 private static String encodeStr(String plainText){ 
    byte[] b=plainText.getBytes(); 
    Base64 base64=new Base64(); 
    b=base64.encode(b); 
    String s=new String(b); 
   return s; 
 } app

 public static void main(String[] args) {
  SendRemoteResult result=new SendRemoteResult();
  String su=result.sendResult(123,"11111", "111111", "11@qq.com",1231231231);
  System.out.println(su);
 }ui

相關文章
相關標籤/搜索