2010-08-09 97 views
2

也许这里有人能帮助我...http客户端 - >发送的消息包括符号

我写了一个非常简单的Java HTTP客户端,它发送一个XML作为数据发布到Web服务器。现在奇怪的是,我们的客户报告在postdata中有一个尾随符号。我绝对不知道如何,如果你看看源代码,在那里我删除每一个变量,它可以...

public static void main(String[] args) { 
    try { 
    final URL httpURL = new URL(args[0]); 

    String request = "<root/>"; 

    HttpURLConnection connection = (HttpURLConnection)httpURL.openConnection(); 
    connection.setRequestMethod("POST"); 
    connection.setDoOutput(true); 

    OutputStream os = connection.getOutputStream(); 
    os.write(request.getBytes()); 
    os.close(); 

    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
    String tmp; 
    String xml = new String(); 
    while ((tmp = in.readLine()) != null) { 
     xml = xml.concat(tmp); 
    } 
    connection.getInputStream().close(); 
    connection.disconnect(); 
    System.out.println("Result: " + xml); 
    } catch (Exception e) { 
     System.err.println("Exception ocurred " + e); 
    } 
} 

正如你所看到的,currenlty我们派出一个固定的“XML”,这仅仅是一个标签。

有没有人知道是否有知道的错误或情况,可能会发生类似的事情?

我很感激每一个帮助:)。谢谢!

回答

1

我看不到任何会导致&符号被发送到服务器的问题。我怀疑问题可能出现在服务器端。

尝试使用wireshark或类似的东西来捕获发送到服务器的TCP数据包,看看你是否能看到那里的流浪汉字符。

相关问题