我用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());
}
}
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());
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货