Java进行Http连接时出现invalid http response

weixin_38055863 weixin_38055863 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面是我的代码,不带参数发起Http连接时不会出现invalid Http Response,一带参数就会出现错误。求高手为我解答一下 import java.net.URL; import java.net.URLEncoder; import java.net.HttpURLConnection; import java.io.*; public class Http {     public static final String POST_URL="http://kirasms.sinaapp.com?";     public static void connect() throws IOException{     StringBuffer get_url=new StringBuffer(POST_URL);     get_url.append(URLEncoder.encode("Message=HelloJava","UTF-8"));     URL url=new URL(get_url.toString());     HttpURLConnection connect=(HttpURLConnection)url.openConnection();     connect.connect();     BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));     String line;     while((line=reader.readLine())!=null)      System.out.println(line);     reader.close();     connect.disconnect();   }   public static void main(String[] args){      try{     connect(); }catch(IOException e){     e.printStackTrace(); }   } } 服务器端的处理代码是: <?php echo $_GET['Message']; ?>
...全文
评论 3
收藏 已收藏
分享
返回顶部