小编Bry*_*yan的帖子

带参数的HttpURLConnection

我有一个我传入的URL,看起来像这样

http://somecompany.com/restws/ebi/SVI/4048/?Name=Tra&Brand=Software: WebSphere - Open App Servers
Run Code Online (Sandbox Code Playgroud)

它不喜欢第二个参数(品牌).从浏览器上面的这个查询字符串工作正常,但只要我在Java中执行它就会失败.当我将webservice更改为接受单个参数时,此URL可正常工作

http://somecompany.com/restws/ebi/SVI/4048/?Name=Tra
Run Code Online (Sandbox Code Playgroud)

似乎java遇到了第二个参数的问题.我尝试过逃避角色以及我能想到的其他一切,但似乎没有任何效果.请帮忙!

String uri = "somecompany.com/restws/ebi/SVI/4048/?Name=" 
           + name+ "&Brand=Software: WebSphere - Open App Servers";

URL url;

try {
    url = new URL(uri);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Accept", "application/xml");
}
...
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
1
解决办法
8639
查看次数

标签 统计

java ×1