java - HttpURLConnection URI 不能为空
问题描述
我想向网站发出 GET 请求,但我得到了URI can't be null.
String url = "https://valid_url.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect(); //-> java.lang.IllegalArgumentException: URI can't be null.
为什么我得到URI can't be null
?
PS:我用的是jdk10
解决方案
您的代码运行良好。
我用这个测试了代码:
String url = "https://google.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect();
可能是您访问的 url 不是GET类型。检查一下。
推荐阅读
- typescript - Firestore & Cloud Function:使用我自己的文档 ID 创建新的集合文档
- java - 如何从 url 获取参数值作为字符串
- ssl - Nginx 错误 https 。curl:(35)错误:1408F10B:SSL例程:ssl3_get_record:错误的版本号
- pyspark - Pyspark:如何编写复杂的数据帧计算引导和
- database - 角色的 LDAP 身份验证和数据库实体用户
- javascript - 分配 websocket 消息数据时无法读取未定义的属性
- python - 如何在 Chrome 中修复我的 Python 笔记本?
- scala - 添加稀疏向量 3.0.0 Apache Spark Scala
- laravel - 在 laravel 中使用访问器的问题
- vb.net - 使用 QBSDK 删除 Quickbooks 发票数据时,如何发现显然需要的“对象访问标志”