创建了URL以后,你需要 URL url = new URL(urlString); BufferedReader in = new BufferedReader( new InputStreamReader( url.openStream())); 而后:String inputline = in.readLine();
谢谢 我把代码改成 URL url = new URL("http://localhost/smsweb/testservlet1?result=1"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); BufferedReader in = new BufferedReader(new InputStreamReader(connection. getInputStream())); in.close(); 就好了
URL url = new URL("http://localhost/smsweb/testservlet1?result=2"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); in.close();这样更加精简点,活活
用java.net.HttpURLConnection
或是其他方法
URL url = new URL("http://localhost/smsweb/testservlet1");
建立了连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");如何才能调用testservlet1中的doPost方法
并传参数过去,使testservlet1通过request.getParameter("xxx")的方法得到参数?
URL url = new URL("http://localhost/smsweb/testservlet1");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream()); String name = "result=1";
out.println(name);
out.close();
好像没有起到直接调用
http://localhost/smsweb/testservlet1?result=1
的作用,呵呵
哪位大侠能指点1,2
public String sendSMS()
{
String strResult = "01";
try
{
if(BusinessType.substring(0,1).equals("0"))
{ SMSContent = SMS ;
}
StringBuffer sb = new StringBuffer("http://211.139.140.164:13083/cgi-bin/sendsms?");
// StringBuffer sb = new StringBuffer("http://192.168.0.4:13083/cgi-bin/sendsms?");
sb.append("username=" + URLEncoder.encode(SpName, "UTF-8"));
sb.append("&password=" + URLEncoder.encode(SpPassword, "UTF-8"));
sb.append("&from=" + FromMobile);
sb.append("&to=" + ToMobile);
if(Sub.trim().length() > 0)
{
sb.append("&sub=" + Sub);
}
sb.append("&dcs=65536");
sb.append("&sendtype=" + SendType);
if(KeyWord.trim().length() > 0)
{
sb.append("&keyword=" + URLEncoder.encode(KeyWord, "UTF-8"));
}
if(FeeCode.trim().length() > 0)
{
sb.append("&feecode=" + URLEncoder.encode(FeeCode, "UTF-8"));
}
if(SMSContent.trim().length() > 0)
{
sb.append("&text=" + URLEncoder.encode(SMSContent, "UTF-8"));
}
URL url = new URL(sb.toString());
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openStream()));
String inputline = in.readLine();
if(inputline != null)
{
loginstance.log("发送短信,"+sb.toString()+ " " + inputline);
}
in.close(); if(!(inputline.equals("success:1,failed:0")))
{
loginstance.log("发送短信失败,"+sb.toString()+ " " + inputline);
loginstance.error("发送短信失败,"+sb.toString()+ " " + inputline);
strResult = "FF";
}
}
catch(Exception e)
{
loginstance.log(e,"发送短信失败," + Request);
loginstance.error(e,"发送短信失败," + Request);
strResult = "FF";
}
return strResult;
}
URL url = new URL(urlString);
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openStream()));
而后:String inputline = in.readLine();
我把代码改成
URL url = new URL("http://localhost/smsweb/testservlet1?result=1");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true); BufferedReader in = new BufferedReader(new InputStreamReader(connection.
getInputStream()));
in.close();
就好了
in.close();这样更加精简点,活活