java 调用接口 Server returned HTTP response code: 411 for URL


//中文必须在URLEncoder后传递,编码为gb2312
String content = java.net.URLEncoder.encode("您本次操作的短信验证码为"+code,"gb2312");
//拼接访问短信接口的url
String sendUrl = "http://si.800617.com:4400/SendSms.aspx?un="+uname+"&pwd="+pwd+"&mobile="+clientTel+"&msg="+content;
System.out.println(sendUrl);
URL url = new URL(sendUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("GET");
connection.connect();
String result = "";
InputStreamReader bis = new InputStreamReader(connection.getInputStream(),"gb2312");
int c = 0;
while((c = bis.read()) != -1){
result = result + (char)c;
}
return result;


执行的时候,总是报Server returned HTTP response code: 411 for URL的错误,一开始是报Server returned HTTP response code: 400 for URL的错误,后来URLEncoder.encode设置编码以后就报411的错了,本以为还是中文的问题,后把connection.setRequestMethod("GET");改成GET的就可以,之前是POST。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值