我正在开发node.js代理服务器应用程序,我希望它支持HTTP和HTTPS(SSL)协议(作为服务器).
我目前正在使用node-http-proxy这样的:
const httpProxy = require('http-proxy'),
http = require('http');
var server = httpProxy.createServer(9000, 'localhost', function(req, res, proxy) {
console.log(req.url);
proxy.proxyRequest(req, res);
});
http.createServer(function(req, res) {
res.end('hello!');
}).listen(9000);
server.listen(8000);
Run Code Online (Sandbox Code Playgroud)
我设置我的浏览器使用HTTP代理localhost:8000,它的工作原理.我还想捕获HTTPS请求(即设置我的浏览器以localhost:8000用作HTTPS代理并在我的应用程序中捕获请求).你能帮帮我怎么办?
PS:
如果我订阅upgrade了httpProxy服务器对象的事件,我可以获得请求,但我不知道如何转发请求并向客户端发送响应:
server.on('upgrade', function(req, socket, head) {
console.log(req.url);
// I don't know how to forward the request and send the response to client
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
此 Google存储文档页面指出,You can use a CNAME redirect only with HTTP, not with HTTPS.但我看不出任何理由.谁能解释我为什么?
所以这是使用curl的请求:
curl -XPOST -H content-type:application/json -d "{\"credentials\":{\"username\":\"username\",\"key\":\"key\"}}" https://auth.api.rackspacecloud.com/v1.1/auth
Run Code Online (Sandbox Code Playgroud)
我一直试图用ruby做同样的请求,但我似乎无法让它工作.
我也尝试了几个库,但我无法让它工作.这是我到目前为止所拥有的:
uri = URI.parse("https://auth.api.rackspacecloud.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/v1.1/auth")
request.set_form_data({'credentials' => {'username' => 'username', 'key' => 'key'}})
response = http.request(request)
Run Code Online (Sandbox Code Playgroud)
我得到415不支持的媒体类型错误.
我在我的git服务器上安装了ssl证书和密钥.但是当我尝试通过我的mysysgit中的https进行克隆时,我会收到错误.早些时候它与http工作得很好.无法确定失败的位置
$ git clone https://server.name/git/testing.git
Cloning into 'testing'...
* Couldn't find host server.name in the _netrc file; using defaults
* About to connect() to server.name port 443 (#0)
* Trying server.name...
* Adding handle: conn: 0x274fd60
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x274fd60) send_pipe: 1, recv_pipe: 0
* Connected to server.name(server.name) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: C:\Users\user1\AppData\Local\Programs\Git/bin/curl-ca-bundle.crt
CApath: none
* SSL certificate …Run Code Online (Sandbox Code Playgroud) 建议的方法是将所有不安全的传入请求重定向到HTTPS.我是否需要编写中间件组件?如果是这样,我无法弄清楚如何获取服务器名称.
public class RedirectHttpMiddleware
{
RequestDelegate _next;
public RedirectHttpMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if (context.Request.IsSecure)
await _next(context);
else
{
var server = ""; // How do I get the server name?
context.Response.Redirect("https://" + server + context.Request.Path);
}
}
}
Run Code Online (Sandbox Code Playgroud) 如何在PHP中设置一个在HTTP和HTTPS中都可读的cookie?
如果不可能,可以做些什么?设置两个饼干?
我正在制作一个应用程序,通过在post方法中传递登录凭据,通过HTTPS登录到aspx网站.使用Charles Proxy检查响应时,我可以看到来自seal.verisign.com的SSL握手失败错误,然后我将被带回登录页面.我不确定我需要做些什么才能解决这个问题.
我在iPhone模拟器中测试它.
我无权访问服务器实现.
有任何想法吗?
谢谢!
我正在使用SSL设置nginx服务器.
ssl的域名是www.mydomain.com
我想重定向所有请求:
http://mydomain.com,http://www.mydomain.com和https://mydomain.com来
我目前有以下服务器块设置:
server{
listen 443 ssl;
root /www/mydomain.com/;
ssl_certificate /ssl/domain.crt;
ssl_certificate /ssl/domain.key;
.
.
.
}
server{
listen 80;
server_name mydomain.com;
return 301 https://www.mydomain.com$request_uri;
}
server{
listen 80;
server_name www.mydomain.com;
return 301 https://www.mydomain.com$request_uri;
}
server{
listen ssl 443;
server_name mydomain.com;
return 301 https://www.mydomain.com$request_uri;
}
Run Code Online (Sandbox Code Playgroud)
这目前不起作用,但我不明白为什么不.我可以得到http - > https工作或没有www到 - > www工作的组合,但如上所述混合它们不起作用.
我按照下面的教程创建了一个https服务器 https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server/
程序运行没有错误
但是当我无法在我的chrome中打开https:// localhost:8000时
它总是得到一个 ERR_SSL_PROTOCOL_ERROR
在我的应用程序中,我试图向我的服务器发出 HTTPS POST 请求。但是,我一直收到 SSLHandshakeException - 链验证失败。我尝试使用 POSTMAN 发送请求,但收到了服务器的响应。当我尝试从应用程序发送请求时,什么可能导致此错误?
这是我尝试发送发布请求的代码片段:
public static JSONObject getDataLibConfiguration(Context context) throws HttpRequestException {
int statusCode = 0;
JSONObject commonInformation;
HttpsURLConnection connection = null;
try {
commonInformation = ConfigurationProcessor.getCommonInformation(context);
if (commonInformation == null) {
return null;
}
URL url = new URL(BuildConfig.SERVER_CONFIG_URL);
if (BuildConfig.DEBUG) {
LogUtils.d(TAG, "url = " + url.getPath());
}
connection = getHttpsConnection(url);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Encoding", "gzip");
byte[] gzipped = HttpUtils.gzip(commonInformation.toString());
cos = new CountingOutputStream(connection.getOutputStream()); //<-- This is where I …Run Code Online (Sandbox Code Playgroud)