在 java 中构建 URL使用 OkHttp
正在尝试构建 .我不太了解它,但我从谷歌搜索中写了下面的代码:http://IP:4567/foldername/1234?abc=xyz
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
public class MyUrlConstruct {
public static void main(String a[]){
try {
String protocol = "http";
String host = "IP";
int port = 4567;
String path = "foldername/1234";
URL url = new URL (protocol, host, port, path);
System.out.println(url.toString()+"?");
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
}
}
我能够建立网址。我被困在查询部分。请帮助我向前迈进。http://IP:port/foldername/1234?