Nginx正向代理请求https报400 您所在的位置:网站首页 nginx转发400 Nginx正向代理请求https报400

Nginx正向代理请求https报400

#Nginx正向代理请求https报400| 来源: 网络整理| 查看: 265

如题,Nginx配置正向代理,请求https时报400,请求http时正常。 Nginx正向代理配置如下:

#正向代理 server { resolver 8.8.8.8;#指定dns服务器 listen 30000; access_log D:/mysoft/nginx-1.17.3/logs/proxy_access.log; error_log D:/mysoft/nginx-1.17.3/logs/proxy_error.log; location / { proxy_pass $scheme://$http_host$request_uri; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $host; proxy_set_header X-Forwarded-For $host; proxy_buffering on; proxy_buffer_size 32k; proxy_busy_buffers_size 256k; proxy_buffers 256 4k; proxy_max_temp_file_size 0; proxy_connect_timeout 30; proxy_cache_valid 200 302 10m; proxy_cache_valid 301 1h; proxy_cache_valid any 1m; } }

使用JDK原生 HttpURLConnection 发送http请求

public static String sendProxyPost(String url, String param, String method, boolean proxy) { OutputStreamWriter out = null; BufferedReader in = null; StringBuffer result = new StringBuffer(); try { URL realUrl = new URL(url); HttpURLConnection conn = null; if (proxy) { Proxy proxy1 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("172.203.144.6", 30000)); conn = (HttpURLConnection) realUrl.openConnection(proxy1); } else { conn = (HttpURLConnection) realUrl.openConnection(); } if(url.indexOf("https")==0){ trustAllCertificates(conn);//信任所有证书 } if (method.equalsIgnoreCase("POST")) { conn.setDoOutput(true); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestMethod("POST");// POST方法 // 设置通用的请求属性 conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } else if (method.equalsIgnoreCase("GET")) { conn.setDoOutput(false); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestMethod("GET"); } conn.connect(); if (method.equalsIgnoreCase("POST")){ out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8"); out.write(param); out.flush(); } in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result.append(line); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != out) { try { out.close(); } catch (IOException e) { System.out.println("e.printStackTrace():{}" + e); } } if (null != in) { try { in.close(); } catch (IOException e) { System.out.println("e.printStackTrace():{}" + e); } } } return result.toString(); }

java通过代理请求百度首页

public static void main(String[] args) { String url; //url = "http://www.formysql.com/mysql/"; url = "https://www.baidu.com"; String s = ErolyTests.sendProxyPost(url,"", "GET",true); System.out.println(s); }

运行结果 在这里插入图片描述 没有得到解决



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有