public String post(String url, String data, String authorization) { StringBuilder sb = new StringBuilder(); try { URL _url = new URL(url); if (url.toLowerCase().contains("https://")) { HttpsHandler httpsH = new HttpsHandler(); httpsH.trustAllHttpsCertificates(); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); HttpsURLConnection sconn = (HttpsURLConnection) _url .openConnection(); sconn.setRequestMethod("POST"); sconn.setDoInput(true); sconn.setDoOutput(true); //application/x-www-form-urlencoded application/json sconn.setRequestProperty("Content-Type", "application/json"); sconn.setRequestProperty("Accept", "application/json"); sconn.setRequestProperty("Authorization", authorization); //往服务器端写内容 if(null!=data){ OutputStream os=sconn.getOutputStream(); os.write(data.getBytes()); os.close(); } //读取服务器端返回的内容 InputStream is=sconn.getInputStream(); InputStreamReader isr=new InputStreamReader(is,"utf-8"); BufferedReader br=new BufferedReader(isr); String line=null; while((line=br.readLine())!=null){ sb.append(line); } } } catch (Exception e) { e.printStackTrace(); } return sb.toString(); } [图片] 80 行报错调用的方法
微信jsapi统一下单接口,返回401在本地请求可以请求通过获取预付单id,服务器上获取的参数通过postman请求可以成功获取预付单id,但是服务器上请求一直不行。请问一下是什么原因 [图片]
2021-05-10