小编Sw0*_*0ut的帖子

如何使用带有代理服务器的 axios 进行 https 调用?

这里基本上是同样的问题

我正在使用浏览器。以下代码由 webpack 编译。我试过这个:

const axios = require('axios');

var res = await axios.get('https://api.ipify.org?format=json', {
    proxy: {
        host: 'proxy-url',
        port: 80,
        auth: {username: 'my-user', password: 'my-password'}
    }
});
console.log(res.data); // gives my ip and not the proxy's one.
Run Code Online (Sandbox Code Playgroud)

我也用相同的代码尝试过这个,但它不起作用:

const axios = require('axios-https-proxy-fix');
Run Code Online (Sandbox Code Playgroud)

然后,我尝试使用 httpsAgent:

const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent')

var agent = new HttpsProxyAgent('http://my-user:my-pass@proxy-url:port');
var res = await axios.get('https://api.ipify.org?format=json', {
    httpsAgent: agent,
});
console.log(res.data); // gives my ip and not the proxy's one.
Run Code Online (Sandbox Code Playgroud)

这是一个错误吗?我是被诅咒了还是我在阅读文档时遇到了问题?

javascript axios

11
推荐指数
2
解决办法
4万
查看次数

HttpRequest和XMLHttpRequest的真正区别

阅读前注意

这不是what-are-differences-between-xmlhttprequest-and-httprequest的副本 。有关信息,我尝试了这个lib,但没有成功,因为它复制了XMLHttpRequest的结构,但实际上并不像它。


我想知道HttpRequestNode和XMLHttpRequest浏览器之间真正的网络区别是什么。

如果我只是在chrome的devtools中观看XMLHttpRequest,则X-Requested-with在请求中看不到任何标头。

此外,CloudFlare的WAF支持自定义规则的在线服务。如果我使用发出请求XMLHttpRequest,它就可以使用,但是我https.request无法通过CF对其进行防火墙保护。

我需要这样做,HttpRequest以便可以配置代理。

两者之间的网络区别是什么?如何从HttpRequest模拟XMLHttpRequest?那有可能吗?我在这里观看了铬的来源,但找不到任何有趣的东西。

可能与IO层不同吗?TCP握手?

需要建议。谢谢


编辑

这是XMLHttpRequest(正在工作)

let req = new XMLHttpRequest();
req.open("post", "https://haapi.ankama.com/json/Ankama/v2/Api/CreateApiKey", true);
req.withCredentials = true;
req.setRequestHeader('Accept', 'application/json');
req.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
req.setRequestHeader('Accept-Encoding', 'gzip, deflate, br');
req.onload = function() {
    console.log(req.response)
};
req.send("login=smallladybug949&password=Tl9HDKWjusopMWy&long_life_token=true");
Run Code Online (Sandbox Code Playgroud)

与cURL相同(不通过CF的防火墙)

curl 'URL' \
-H 'origin: null' \
-H 'accept-encoding: gzip, deflate, br' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0.1; Z988 Build/MMB29M) AppleWebKit/537.36 (KHTML, like …
Run Code Online (Sandbox Code Playgroud)

javascript networking xmlhttprequest httprequest

7
推荐指数
1
解决办法
335
查看次数

流星 - 没有"findOne"功能的回调

我正在研究一个Meteor项目,我必须说这根本不容易,特别是对于一件事:回调!

一切都是异步的,所以我想知道如何从我的mongodb获得结果.

var user = Meteor.users.findOne({username: "john"});
return (user); // sometimes returns "undefined"
Run Code Online (Sandbox Code Playgroud)

...

var user = Meteor.users.findOne({username: "john"});
if (user)                    // so ok, I check if it exists!
    return (user);           // Cool, I got my user!
return ();                   // Ok and what should I return here? I want my user!
Run Code Online (Sandbox Code Playgroud)

我不想变脏,像setTimeout一样放在各处.有人有解决方案吗?


编辑: 我注意到在router.js中使用console.log,我的数据被返回4次.带有未定义值的2次,带有预期值的2次.在视图中,它仍然未定义.为什么路由器在此路由中传递了4次?它是否显示路由器中返回值的第一个结果?

如果find()没有找到任何内容,我应该返回什么?


编辑2:这是一些需要理解的代码.

this.route('profilePage', {
    path: 'profil/:_id?',
    waitOn: function() {
        return [
        Meteor.subscribe('article', { prop: this.params._id}), // id can be id or username
        Meteor.subscribe('article', { userId: …
Run Code Online (Sandbox Code Playgroud)

mongodb meteor

6
推荐指数
1
解决办法
5395
查看次数

在java 8中构建maven程序集

我在我的Project中更改了使用的java版本.现在我正在使用lambdas表达式.

如果我编译IDE(IntelliJ),它运行良好.但是当我使用maven:assembly进行编译时,它会失败.

这是输出:

[ERROR] ...../commands/parser/CommandParser.java:[141,73] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
Run Code Online (Sandbox Code Playgroud)

和我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lefrantguillaume</groupId>
<artifactId>ServerTinyTank</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>

<dependencies>
    <dependency>
        <groupId>com.esotericsoftware</groupId>
        <artifactId>kryonet</artifactId>
        <version>2.22.0-RC1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>args4j</groupId>
        <artifactId>args4j</artifactId>
        <version>2.32</version>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.lefrantguillaume.Main</mainClass> …
Run Code Online (Sandbox Code Playgroud)

maven-assembly-plugin java-8

3
推荐指数
1
解决办法
6578
查看次数

Bash:在设备上写入然后从中读取

我正在开发一个非常小的程序,其重量传感器连接到S0.以下是我初始化串口的方法:

stty -F /dev/ttyS0 9600 min 60 time 1 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke parenb -ixon
Run Code Online (Sandbox Code Playgroud)

我已经测试了几种写入设备的方式,然后从中读取:

echo IDN? >> /dev/ttyS0
read -t1 output < /dev/ttyS0   # waits for ever here.
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

echo IDN? >> /dev/ttyS0 && read -t1 output < /dev/ttyS0  # waits too
Run Code Online (Sandbox Code Playgroud)

但不成功.在一行中,它不会改变任何东西.

until read -t1 < /dev/ttyS0; do
    echo IDN? > /dev/ttyS0
done
identity=$(echo $REPLY | tr -d $'\r')
Run Code Online (Sandbox Code Playgroud)

这在连接设备时有效.


对于我的测试,我做了这个,它工作:

$ cat /dev/ttyS0 &
[1] 9188 …
Run Code Online (Sandbox Code Playgroud)

bash device read-write

3
推荐指数
1
解决办法
1379
查看次数