我用Java写了一段代码来发送一个字符串给一个ASP.net URL,当是一个简单的字符串时,可以收到回答,显示出URL的页面内容但当换成XML的字符串时,返回Server returned HTTP response code: 500 for URL:http://10.100.32.65/test/login.aspx这个url是真实存在的,当把message="this is a test"时可以成功,并读取URL的页面内容把它发给asp也面是可以成功读出来的,所以感觉这是asp.net的问题请问高人有人知道根本原因吗public static void main(String[] args) {
HttpURLConnection connection = null;   
        BufferedReader in = null;   
        try {   
            String message="<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"LR-1-6QcnfTsfFMDmalJphenILMNwQUTJyUYAGgs\" Version=\"2.0\" IssueInstant=\"2009-12-24T09:36:11Z\"><saml:NameID xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">@NOT_USED@</saml:NameID><samlp:SessionIndex>ST-1-9pd4anx1IpLjL50DoGNX-localhost</samlp:SessionIndex></samlp:LogoutRequest>";
            
            String url="http://10.100.32.65/test/login.aspx";
            
            final URL logoutUrl = new URL(url);
            
            final String output = "logoutRequest=" + URLEncoder.encode(message, "UTF-8");            connection = (HttpURLConnection) logoutUrl.openConnection();
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setReadTimeout(5000);
            connection.setConnectTimeout(5000);
            connection.setRequestProperty("Content-Length", Integer.toString(output.getBytes().length));
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            final DataOutputStream printout = new DataOutputStream(connection.getOutputStream());
            printout.writeBytes(output);
            printout.flush();
            printout.close();            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            
            String str=in.readLine();
            while (str != null) {
             System.out.println("str="+str);
                str=in.readLine();
            }   
     }
        catch(Exception e)
        {
          System.out.println(e.getMessage());
        }
        
}

解决方案 »

  1.   

    String message="<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"LR-1-6QcnfTsfFMDmalJphenILMNwQUTJyUYAGgs\" Version=\"2.0\" IssueInstant=\"2009-12-24T09:36:11Z\"><saml:NameID xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">@NOT_USED@</saml:NameID><samlp:SessionIndex>ST-1-9pd4anx1IpLjL50DoGNX-localhost</samlp:SessionIndex></samlp:LogoutRequest>";
                
      

  2.   

    实际传送的值是url encoding后的logoutRequest=%3Csamlp%3ALogoutRequest+xmlns%3Asamlp%3D%22urn%3Aoasis%3Anames%3Atc%3ASAML%3A2.0%3Aprotocol%22+ID%3D%22LR-1-6QcnfTsfFMDmalJphenILMNwQUTJyUYAGgs%22+Version%3D%222.0%22+IssueInstant%3D%222009-12-24T09%3A36%3A11Z%22%3E%3Csaml%3ANameID+xmlns%3Asaml%3D%22urn%3Aoasis%3Anames%3Atc%3ASAML%3A2.0%3Aassertion%22%3E%40NOT_USED%40%3C%2Fsaml%3ANameID%3E%3Csamlp%3ASessionIndex%3EST-1-9pd4anx1IpLjL50DoGNX-localhost%3C%2Fsamlp%3ASessionIndex%3E%3C%2Fsamlp%3ALogoutRequest%3E