用Java发get请求响应不正确

我现在要封装网页版微信客户端的接口。在封装获取联系人列表的方法里面,我要通过get请求把参数发出去,请求网址如下:

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?pass_ticket=w4mJvFCkNL8jhdqd5gFscDcClX0eBrV%2FkkIsE%2FrEDqfIWpO%2BEIpEepo77M6E87OZ&r=1525134953248&seq=0&skey=@crypt_dfce2a98_7dc1c34a13beb53387ca0f2cbbf14617

然后获得如下的响应
图片描述

可是当我代码这样写的时候:

final long l = System.currentTimeMillis();//返回当前的计算机时间

String res = Http.sendGet("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact","pass_ticket="+pass_ticket+"&r="+l+"&seq=0&skey="+skey);

返回的结果却是这样的:

{"BaseResponse": {"Ret": 1,"ErrMsg": ""},"MemberCount": 0,"MemberList": [],"Seq": 0}

请问我哪里写错了,我用的get方法是这样的

public static String sendGet(String url, String param) {

String result = "";

BufferedReader in = null;

try {

String urlNameString = url + "?" + param;

URL realUrl = new URL(urlNameString);

// 打开和URL之间的连接

URLConnection connection = realUrl.openConnection();

// 设置通用的请求属性

connection.setRequestProperty("accept", "*/*");

connection.setRequestProperty("connection", "Keep-Alive");

connection.setRequestProperty("user-agent",

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

// 建立实际的连接

connection.connect();

// 获取所有响应头字段

Map<String, List<String>> map = connection.getHeaderFields();

// 遍历所有的响应头字段

for (String key : map.keySet()) {

System.out.println(key + "--->" + map.get(key));

}

// 定义 BufferedReader输入流来读取URL的响应

in = new BufferedReader(new InputStreamReader(

connection.getInputStream()));

String line;

while ((line = in.readLine()) != null) {

result += line;

}

} catch (Exception e) {

System.out.println("发送GET请求出现异常!" + e);

e.printStackTrace();

}

// 使用finally块来关闭输入流

finally {

try {

if (in != null) {

in.close();

}

} catch (Exception e2) {

e2.printStackTrace();

}

}

return result;

}

回答:

String res = Http.sendGet("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact","pass_ticket="+pass_ticket+"&r="+l+"&seq=0&skey"+skey);

最后skey少个等号

String res = Http.sendGet("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact","pass_ticket="+pass_ticket+"&r="+l+"&seq=0&skey="+skey);

以上是 用Java发get请求响应不正确 的全部内容, 来源链接: utcz.com/p/173942.html

回到顶部