以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  为什么我这段代码取不到结果(socket post xml)  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=6941)


--  作者:leanyee
--  发布时间:4/22/2004 4:24:00 PM

--  为什么我这段代码取不到结果(socket post xml)
public static void main(String[] args) {
    String s1 = "<?xml version=\"1.0\"?>" +
        "<SLIR ver=\"1.1\" ext=\"1.0\">" +
        "<CLIENT>" +
        "<ID>lcsguodu1</ID>" +
        "<PWD>lcsguodu</PWD>" +
        "</CLIENT>" +
        "<SERVICE_ID>servicegd-1</SERVICE_ID>" +
        "<REQUESTER>8613705938687</REQUESTER>" +
        "<MSIDS>" +
        "<MSID msid_type=\"MSISDN\" msid_enc=\"ASC\">8613705938687</MSID>" +
        "</MSIDS>" +
        "<GEO_INFO coord_sys=\"LL\" datum=\"WGS-84\">" +
        "<FORMAT format_type=\"LL\">ID9</FORMAT>" +
        "</GEO_INFO>" +
        "<PRIO prio_type=\"HIGH\"/>" +
        "</SLIR>";
/*   String s = "POST /LocationRequest/ HTTP/1.1" + "\n" +
        "Host: 211.138.155.253:701" + "\n" +
        "Content-type: text/xml" + "\n" +
        "Content-length:" + s1.length() + "\n\n";
*/
    String s = "POST http://211.138.155.253:701/LocationRequest "+
        "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* "+
        "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) "+
        "Content-Type:  application/x-www-form-urlencoded "+
        "Content-Length:"+s1.length()+ " "+
//        "Host: 211.138.155.253 "+
        "Data: "+s1;
    try {
      Socket socket = new Socket("211.138.155.253", 701);
      socket.setSoTimeout(100000);

      BufferedOutputStream out = new BufferedOutputStream(socket.
          getOutputStream());
      DataInputStream in = new DataInputStream(socket.getInputStream());
      out.write(s.getBytes(), 0, s.length());
      out.flush();

      StringBuffer bs = new StringBuffer();
      String responseLine;
      while ( (responseLine = in.readLine()) != null) {
          bs.append(responseLine + "\n");
      }

      String responsedata = bs.toString();
      in.close();
      out.close();

      socket.close();
      System.out.println(s);
      System.out.println(responsedata);
    }
    catch (IOException e) {
      System.out.println(e.getMessage());
    }
  }


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms