private void RequestWithPara(Map<String,String> paras,String requestMethod,String api) {
String stringUrl = "";
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("?");
if(paras != null && paras.size() > 0){
Iterator<Map.Entry<String, String>> iterator = paras.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry<String, String> next = iterator.next();
stringBuilder.append(next.getKey());
stringBuilder.append("=");
stringBuilder.append(next.getValue());
if(iterator.hasNext()){
stringBuilder.append("&");
}
}
}
if(stringBuilder.length() > 0){
stringUrl = BASE_URL + api +stringBuilder.toString();
}
else{
stringUrl = BASE_URL + api;
}
try {
URL url = new URL(stringUrl);
Log.v(TAG,stringUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(5000);
httpURLConnection.setRequestMethod(requestMethod);
httpURLConnection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9");
httpURLConnection.setRequestProperty("Accept","*/*");
httpURLConnection.connect();
int responseCode = httpURLConnection.getResponseCode();
Log.v(TAG,String.valueOf(responseCode));
if(responseCode == HttpURLConnection.HTTP_OK){
InputStream inputStream = httpURLConnection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String dataJson = bufferedReader.readLine();
Log.v(TAG,dataJson);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
if(bufferedReader != null){
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
这是我根据拉锯哥视频学习边打的代码,查了半小时不知道哪里有问题,下面是我的log图,麻烦大佬们帮小白解惑下

400呀,badrequest
请求参数不对||请求方法不对||请求路径不对。为什么要遮挡住呢?看样子不像是你私人的ip呀。
被卡住在这里是真的太难受辽