public static String sendPost("http://xxxxx/send/send.aspx","name=aa&pwd=bb&tel=12345678901&msg=cc") {
String result = "";
try {
URL httpurl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) httpurl
.openConnection();
System.out.println(httpConn.getRequestMethod());

httpConn.setRequestMethod("POST");
System.out.println(httpConn.getRequestMethod());
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
PrintWriter out = new PrintWriter(httpConn.getOutputStream());
out.print(param);
out.flush();
System.out.println(httpurl.toString());
String file = httpurl.getFile();
String host = httpurl.getHost();
String path = httpurl.getPath();
String protocol = httpurl.getProtocol();
String query = httpurl.getQuery();
String ref = httpurl.getRef();
String userInfo = httpurl.getUserInfo();
// String content = (String) httpurl.getContent();
String authority = httpurl.getAuthority();
int port = httpurl.getPort();
System.out.println("file--" + file);
System.out.println("host--" + host);
System.out.println("path--" + path);
System.out.println("protocol--" + protocol);
System.out.println("query--" + query);
System.out.println("ref--" + ref);
System.out.println("userInfo--" + userInfo);
// System.out.println("content--" + content);
System.out.println("authority--" + authority);
System.out.println("port--" + port);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(
httpConn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
in.close();
} catch (Exception e) {
System.out.println("没有结果!" + e);
}
return result;
}
url = http://xxxxx/send/send.aspx;的话就是不能带上参数一起传过去。但如果我换了url是以***.do或者.jsp结尾的都没有问题。
这是asp.net的问题吗。我该怎么做才能用post方式把参数提交过去呢。再有就是,我用get方式提交这个也是没问题的。下面是用get方式提交的方法:public static String sendGet(String tel, String msg) {
String result = "";
try {
String urlName = "http://xxxxx/send/send.aspx" + "?"
+ "name=aa&pwd=bb&dst=" + tel + "&msg=" + msg;
URL U = new URL(urlName);
URLConnection connection = U.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));

String line;
while ((line = in.readLine()) != null) {
result += line;
}
in.close();
} catch (Exception e) {
System.out.println("没有结果!" + e);
}
return result;
}