新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Java, J2SE, J2ME, J2EE, 以及Eclipse, NetBeans, JBuilder等Java开发环境,还有JSP, JavaServlet, JavaBean, EJB以及struts, hibernate, spring, webwork2, Java 3D, JOGL等相关技术。
    [返回] 计算机科学论坛计算机技术与应用『 Java/Eclipse 』 → [求助] 救命啊!!搞了2天了,快疯了!!!救救我!!! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6473 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助] 救命啊!!搞了2天了,快疯了!!!救救我!!! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     秋风细雨 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:52
      门派:XML.ORG.CN
      注册:2004/9/20

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给秋风细雨发送一个短消息 把秋风细雨加入好友 查看秋风细雨的个人资料 搜索秋风细雨在『 Java/Eclipse 』的所有贴子 引用回复这个贴子 回复这个贴子 查看秋风细雨的博客楼主
    发贴心情 [求助] 救命啊!!搞了2天了,快疯了!!!救救我!!!

    功能是发送xml,得到xml的回馈, 是用人家一个短信接口,接受xml包..然后发过去处理包.

    高手们,救救我!

    //package xml;

    import org.jdom.*;
    import org.jdom.output.*;
    import org.jdom.input.*;

    import java.io.*;
    import java.net.*;

    public class zsi_mt {
          private String cp_code = "";
          private String dest_num = "";
          private String src_num = "";
          private String service_code = "";
          private String content = "";
          HttpURLConnection conn = null;
          BufferedReader br = null;
          DataOutputStream dos = null;
          DataInputStream inStream = null;
          String urlString = "http://10.100.148.123:80";
          InputStream is = null;
          OutputStream os = null;
          boolean ret = false;
          String StrMessage = "";
          int bytesRead, bytesAvailable, bufferSize;
          byte[] buffer;
          int maxBufferSize = 1 * 1024 * 1024;
          String responseFromServer = "";

          public Document CreateXML() {

                Element root = new Element("mt");
                Document doc = new Document(root);
                Element e1 = new Element("billing");
                Element mtbill = root.addContent(e1);
                Element el_cp_code = e1.addContent(new Element("cp_code").setText(
                    cp_code));
                Element el_dest_num = e1.addContent(new Element("dest_num").setText(
                    dest_num));
                Element el_src_num = e1.addContent(new Element("src_num").setText(
                    src_num));
                Element el_service_code = e1.addContent(new Element("service_code").
                    setText(service_code));
                Element el1 = new Element("plan");
                el1.setAttribute("id", "PI01");
                Element plan = root.addContent(el1);
                return doc;

          }

          public void SendXML(Document doc) {
                try {
                      URL url = new URL(urlString);
                      conn = (HttpURLConnection) url.openConnection();
                      conn.setDoInput(true);
                      conn.setDoOutput(true);
                      conn.setUseCaches(false);
                      conn.setRequestMethod("POST");
                      conn.setRequestProperty("Connection", "Keep-Alive");
                      System.out.println("22222");
                      org.jdom.output.XMLOutputter xmlout = new org.jdom.output.
                          XMLOutputter(" ", true, "gb2312");
                      OutputStream os = conn.getOutputStream();
                      xmlout.output(doc, os);

                      dos = new DataOutputStream(os);

                      dos.flush();
                      dos.close();

                      try {
                            inStream = new DataInputStream(conn.
                                getInputStream());

                            try {
                                  SAXBuilder sb = new SAXBuilder(); // 新建立构造器
                                  Document indoc = sb.build(inStream);
                                  XMLOutputter outputter = new XMLOutputter("  ", true);
                                  outputter.output(indoc, System.out);
                            }
                            catch (Exception ex) {
                                  ex.printStackTrace();
                            }

                            inStream.close();

                      }
                      catch (IOException ioex) {
                            ioex.printStackTrace();


                      }

                }
                catch (MalformedURLException ex) {
                       ex.printStackTrace();
                }

                catch (IOException ioe) {
                       ioe.printStackTrace();
                }

          }

          public String GetinStream(InputStream in) {
                return ("11");

          }

          public void setCp_code(String cp_code) {
                this.cp_code = cp_code;
          }

          public void setDest_num(String dest_num) {
                this.dest_num = dest_num;
          }

          public void setSrc_num(String src_num) {
                this.src_num = src_num;
          }

          public void setService_code(String service_code) {
                this.service_code = service_code;
          }

          public void setContent(String content) {
                this.content = content;
          }

          public static void main(String[] args) throws Exception {
                zsi_mt mt1 = new zsi_mt();
                mt1.setCp_code("hs");
                mt1.setDest_num("13311820455");
                mt1.setSrc_num("4545");
                mt1.setService_code("SHYHJ");
                mt1.setContent("ben test 0920");
                Document doc = mt1.CreateXML();
                try {
                      XMLOutputter outputter = new XMLOutputter("  ", true);
                      outputter.output(doc, System.out);
                }
                catch (java.io.IOException e) {
                      e.printStackTrace();
                }
                System.out.println("111");
                mt1.SendXML(doc);

          }

    }

    java.io.FileNotFoundException:  72 出错!


    谢谢大家了!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/9/20 19:17:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Java/Eclipse 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/12/27 19:34:17

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms