java 获取“http://192.168.1.120:8081/as/qwe/er?a=1”中请求地址
时间: 2023-11-25 10:07:02 浏览: 76
您可以使用Java中的URL类来解析URL并获取请求地址。以下是一个示例代码:
```java
import java.net.URL;
public class UrlParser {
public static void main(String[] args) throws Exception {
String urlStr = "http://192.168.1.120:8081/as/qwe/er?a=1";
URL url = new URL(urlStr);
String path = url.getPath();
System.out.println("请求地址为:" + path);
}
}
```
上述代码将输出:
```
请求地址为:/as/qwe/er
```
其中,`getPath()`方法返回URL的路径部分,即请求地址。
相关问题
根据这个urlhttp://122.96.69.34:20080/index/api/addFFmpegSource?secret=a55d78fa-0961-a891-321a-96eb561933c7&src_url=rtsp://admin:qwe123456@192.168.6.1:8702&dst_url=rtmp://122.96.69.34:10554/app/test&timeout_ms=10000&enable_hls=false&enable_mp4=false,用java代码实现rtsp拉取视频流接口
好的,以下是Java代码实现rtsp拉取视频流接口的示例:
```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class RtspPullApiDemo {
public static void main(String[] args) {
try {
String url = "http://122.96.69.34:20080/index/api/addFFmpegSource?secret=a55d78fa-0961-a891-321a-96eb561933c7&src_url=rtsp://admin:qwe123456@192.168.6.1:8702&dst_url=rtmp://122.96.69.34:10554/app/test&timeout_ms=10000&enable_hls=false&enable_mp4=false";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
上述代码中,我们使用Java内置的HttpURLConnection类来发送GET请求,并获取响应结果。其中url变量即为我们要调用的API接口地址。
注意,这里的rtsp拉取视频流接口需要传入一些参数,如src_url、dst_url等,具体参数含义可以参考API文档进行调整。
希望这个示例对你有所帮助!
根据这个url,http://122.96.69.34:20080/index/api/addFFmpegSource?secret=a55d78fa-0961-a891-321a-96eb561933c7&src_url=rtsp://admin:qwe123456@192.168.6.1:8702&dst_url=rtmp://122.96.69.34:10554/app/test&timeout_ms=10000&enable_hls=false&enable_mp4=false,设计一套java代码实现拉取rtsp视频流的接口
好的,根据您提供的URL,我可以给出以下Java代码实现拉取rtsp视频流的接口:
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class RtspPuller {
public static void main(String[] args) {
String secret = "a55d78fa-0961-a891-321a-96eb561933c7";
String srcUrl = "rtsp://admin:qwe123456@192.168.6.1:8702";
String dstUrl = "rtmp://122.96.69.34:10554/app/test";
int timeoutMs = 10000;
boolean enableHls = false;
boolean enableMp4 = false;
String apiUrl = "http://122.96.69.34:20080/index/api/addFFmpegSource" +
"?secret=" + secret +
"&src_url=" + srcUrl +
"&dst_url=" + dstUrl +
"&timeout_ms=" + timeoutMs +
"&enable_hls=" + enableHls +
"&enable_mp4=" + enableMp4;
try {
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
这个程序会向您提供的URL发送一个GET请求,并输出响应结果。您可以根据需要在程序中进行修改。
阅读全文