自己用

来源:互联网 发布:潘建伟事件 知乎 编辑:程序博客网 时间:2024/05/07 12:28

URL url = null;
  HttpURLConnection httpurlconnection = null;
  try {
   url = new URL("http://211.147.222.30/se/sseS");
   // 以post方式请求
   httpurlconnection = (HttpURLConnection) url.openConnection();
   httpurlconnection.setConnectTimeout(6000);
   httpurlconnection.setReadTimeout(6000);
   httpurlconnection.setDoOutput(true);
   httpurlconnection.setRequestMethod("POST");
   msg=java.net.URLEncoder.encode(msg,"utf-8");
   String username = "UserName=user&Password=pwd&SrcNumber=1065&DestTermID="
    + dest+ "&MsgContent=" + msg;
  
   httpurlconnection.getOutputStream().write(
     username.getBytes("utf-8"));
   httpurlconnection.getOutputStream().flush();
   httpurlconnection.getOutputStream().close();
   // 获取响应代码
   code = httpurlconnection.getResponseCode();
   // 获取页面内容
   java.io.InputStream in = httpurlconnection.getInputStream();
   java.io.BufferedReader breader = new BufferedReader(
     new InputStreamReader(in, "gb2312"));
   String str = breader.readLine();
   while (str != null) {
    resp+=str;
    str= breader.readLine();
   }
  } catch (Exception e) {
   resp="err";
  
  } finally {
   if (httpurlconnection != null)
    httpurlconnection.disconnect();
   }

URL url = null;
  HttpURLConnection httpurlconnection = null;
  try {
   url = new URL("http://211.147.222.30/se/sseS");
   // 以post方式请求
   httpurlconnection = (HttpURLConnection) url.openConnection();
   httpurlconnection.setConnectTimeout(6000);
   httpurlconnection.setReadTimeout(6000);
   httpurlconnection.setDoOutput(true);
   httpurlconnection.setRequestMethod("POST");
   msg=java.net.URLEncoder.encode(msg,"utf-8");
   String username = "UserName=user&Password=pwd&SrcNumber=1065&DestTermID="
    + dest+ "&MsgContent=" + msg;
  
   httpurlconnection.getOutputStream().write(
     username.getBytes("utf-8"));
   httpurlconnection.getOutputStream().flush();
   httpurlconnection.getOutputStream().close();
   // 获取响应代码
   code = httpurlconnection.getResponseCode();
   // 获取页面内容
   java.io.InputStream in = httpurlconnection.getInputStream();
   java.io.BufferedReader breader = new BufferedReader(
     new InputStreamReader(in, "gb2312"));
   String str = breader.readLine();
   while (str != null) {
    resp+=str;
    str= breader.readLine();
   }
  } catch (Exception e) {
   resp="err";
  
  } finally {
   if (httpurlconnection != null)
    httpurlconnection.disconnect();
   }