[Golang]开启本地代理下Golang进行Http请求

网络代理【4】ReverseProxy源码分析及使用 真机侧 package main type RealServer struct { Addr string } func NewRealServer(addr string) *RealServer { return &RealServer{Addr: addr} } func (r *RealServer) HelloHandler(w http.ResponseWriter, req *http.Request) { //127.0.0.1:8008/abc?sdsdsa=11 . 阅读详情

当本地开启翻墙软件的时候,明明浏览器可以访问,但是用golang的http包却不能访问,为什么会这样尼,其实golang的http走网络7层模型中偏下层,没有走位于上层翻墙软件的代理接口,因此golang的http无法访问,那么如何使用翻墙软件接口尼?需要配置下proxyURL, err := url.Parse(“http://127.0.0.1:10871”)其中的协议一般为http(也可以是socks)ip地址127.0.0.1不用改,端口按照实际的接口修改。


package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
)

func main() {
	// 创建一个代理地址
	proxyURL, err := url.Parse("http://127.0.0.1:10871")
	if err != nil {
		log.Fatal(err)
	}

	// 创建一个 Transport 实例,并配置代理
	transport := &http.Transport{
		Proxy: http.ProxyURL(proxyURL),
	}

	// 使用自定义的 Transport 实例创建一个 http.Client
	client := &http.Client{
		Transport: transport,
	}
	req, err := http.NewRequest("GET", "https://www.sehuatang.org", nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36")
	req.Header.Set("Cookie", "_safe=vqd37pjm4p5uodq339yzk6b7jdt6oich; cPNj_2132_saltkey=a5ffFKLd; cPNj_2132_lastvisit=1691752561; cPNj_2132_atarget=1; cPNj_2132_lastfp=6a9c7553e07b9f17e0dfa4f579361059; cPNj_2132_home_diymode=1; cPNj_2132_st_p=0%7C1692189681%7Cda20216937156c4d30b129e0d1859b42; cPNj_2132_viewid=tid_1493743; cPNj_2132_visitedfid=2D141D95D103D155D50D104D125D137D117; cPNj_2132_st_t=0%7C1692237351%7C5d8bcdb21881240dea376ba85b69c733; cPNj_2132_forum_lastvisit=D_152_1689677645D_142_1689771242D_139_1691155745D_37_1691493914D_41_1691756168D_154_1691756172D_36_1691773699D_43_1691773703D_48_1691773707D_49_1691773720D_165_1691773721D_96_1691774864D_145_1691817372D_146_1691829223D_155_1691835420D_109_1691836159D_143_1691836161D_103_1691911090D_117_1691927224D_137_1691927238D_125_1691927977D_104_1691927989D_50_1692067574D_95_1692194604D_141_1692237349D_2_1692237351; cPNj_2132_lastact=1692261728%09index.php%09")

	// 发起 HTTP 请求
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	// 读取响应内容
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Response:", string(body))
}

Mediapipe姿态估计——用坐标计算手指关节弯曲角度并实时标注 利用mediapipe搭建姿态检测模型;mediapipe人体标注节点坐标;mediapipe计算手指弯曲角度并实时渲染;mediapipe计算关节弯曲角度。mediapipe手势识别;mediapipe姿态检测模型;mediapipe学习。 阅读详情

相关推荐

聚类模型-层次聚类

聚类模型 1、层次聚类 2、原型聚类-K-means 3、模型聚类-GMM 4、EM算法-LDA主题模型 5、密度聚类-DBSCAN 6、图聚类-谱聚类 一、层次聚类 一、聚类理论 ​ 一般来说,聚类是在训练样本的标签信息不知的情况下,学习样本内在的性质和规律,将有限的集合划分成ccc类。根据“方以类聚,物以群分”的思想,类内对象尽可能的相似,...

myazi 6503

Golang 设置http代理

go POST请求的时候设置http代理,代码直接贴出来。

博士的BLOG 4026

GCC调试黑科技:-fomit-frame-pointer优化下如何保证栈回溯能力

本文深入探讨了GCC编译器在启用`-fomit-frame-pointer`优化选项时如何保证栈回溯能力。通过分析`.eh_frame`段的结构与DWARF调试信息,提供了从编译选项配置到实战调试的完整解决方案,帮助开发者在性能优化与调试能力之间找到最佳平衡点。

u6v7w8x的博客 904

Go语言实现HTTP正向代理

正向代理(Forward Proxy)是一种代理服务器的部署方式,它位于客户端和目标服务器之间,代表客户端向目标服务器发送请求。正向代理可以用来隐藏客户端的真实身份,以及在不同网络环境下实现访问控制、负载均衡、缓存、访问优化等功能。

https://github.com/cv70 1536

STM32G0实战:HAL库与LL库Flash操作避坑指南(附HardFault解决方案)

本文深入剖析了STM32G0系列微控制器在Flash操作中常见的HardFault问题,对比了HAL库与LL库在读写擦除操作上的底层差异与潜在陷阱。文章提供了基于寄存器状态分析的精准调试方法,并给出了经过实战检验的解决方案与健壮的代码框架,帮助开发者有效规避数据丢失与系统崩溃风险。

t8u9v0w1x的博客 730

2025年前端框架全景解析:React、Vue、Angular的生态与未来之争

前端框架的竞争本质是工程哲学的分野:React的灵活、Vue的简洁、Angular的严谨,分别对应不同场景需求。

科技D人生 4843

golang实现http(s)代理

简单原理: 最近需要用golang去实现一个http(s)的代理,简单的解释一下,实现过程就是首先启动一个http(s)的服务,这个很简单,demo一大堆,我就不多说了,接下来要实现代理,很简单的原理就是,通过你实现的http(s)服务接收到来自客户的请求,收到之后通过http.NewRequest建立一次新的请求,当然需要你在配置文件中写明确需要代理到的目标地址和端口,建立新请求到目标地址之后将目标地址返回的数据原封不动的返回给原来的客户端。 注意点: 1、客户端请求的所有头信息,都要原封不动的写入

FlayHigherGT的博客 2988

第4章:外包接单全攻略——Upwork/电鸭/猪八戒从0到第一单

> - 三个外包平台的详细对比(适合人群、抽成、防骗) > - 每个平台的Profile优化模板(可直接复制修改) > - 用AI写Proposal的3个Prompt模板(我实测回复率提升50%) > - 报价策略与防骗指南(附5个危险信号) > - 我的第一单复盘:从注册到收款的全过程(含聊天记录脱敏)

sfishfly的博客 574

Golang http 请求如何设置代理

golang http 请求使用代理和禁用代理

云在青天水在瓶 2513

UG\NX二次开发 替换部件引用集UF_ASSEM_replace_refset

替换部件引用集UF_ASSEM_replace_refset,需要替换成“完整部件(Entire Part)”需要第三个参数传入空指针或者空字符串。

王牌飞行员_里海的博客 255

PCIe 全解析笔记:从协议本质到工程实现

学习 PCIe,最容易陷入的误区是直接跳进协议手册(Base Spec 1300 多页),然后在 TLP 字段、LTSSM 状态、Ordering Rules 中迷失方向。正确的思维路径历史维度:从 PCI 到 PCIe,解决了什么核心矛盾?抽象维度:协议栈分层的真正意图是什么?工程维度:高速串行链路面临哪些物理挑战?协议如何应对?系统维度:作为 CPU 与外设的"动脉",PCIe 如何融入整个计算机体系?带着这四个视角去看每一个细节,知识才能内化为认知。

m0_46644103的博客 261

使用golang启动一个http代理

运行脚本使用浏览器访问http://yourAddr/ssl(如: http://localhost:8080/ssl)下载并安装证书。1.使用前需要先生成证书 然后在代码中替换你的证书路径(自行配置openssl.conf)使用第三方库github.com/elazarl/goproxy。2.对证书进行解密(使用加密证书需进行额外操作)3.使用前需要先下载并安装证书。

qq_41864652的博客 903

电力系统分析 | Matlab实现源荷场景生成---蒙特卡洛法场景生成启发式同步回带削减

电力系统分析 | Matlab实现源荷场景生成---蒙特卡洛法场景生成启发式同步回带削减

前程算法屋的博客 812

Golang 简单 http 代理转发

程序基本实现了对http的完整转发,目前暂不支持https windows需要在设置中的网络>代理设置为手动,并开启代理服务器,填写ip和端口 // httpForward package main import ( "fmt" "io" "io/ioutil" "net/http" "os" ...

波士地盘 655

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

golang 开启HTTP代理认证

内部网路不能直接访问外网接口,可以通过代理发送HTTP请求。HTTP代理服务需要进行认证。

数据库技术 717

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

终极指南:如何使用Go语言的Requests库快速实现高效HTTP请求

想要在Go语言中轻松处理HTTP请求吗?🚀 Go语言的Requests库让你告别复杂的HTTP客户端配置,享受Python Requests般的简洁体验!这个强大的HTTP客户端库专为Golang开发者设计,提供了简单直观的API,让你的网络请求变得异常简单。 ## 🎯 为什么选择Go Requests库? Go语言的Requests库是一个功能完整的HTTP客户端库,它借鉴了Python

gitblog_00069的博客 549

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

go 网络请求包 resty

resty是 Go 语言的一个 HTTP client 库。resty功能十分强大,特性丰富,并提供了简单易用的 API。

码刀攻城 2736

使用Go语言编写自定义的HTTP代理:探险网络奇幻之旅

现在,你可以运行你的Go程序,并启动代理服务器!当有客户端发送请求时,它将自动将请求转发到你指定的目标服务器。你可以根据需要修改处理函数中的逻辑,来实现更丰富的功能。现在,你已经掌握了编写自定义HTTP代理的入门技巧,接下来就可以发挥创意,探索更多有趣的功能了!接下来,我们需要创建一个处理函数来处理客户端的请求和转发请求给目标服务器。最后,我们需要创建一个代理服务器,并将处理函数注册到根路径上。// 例如,你可以将请求转发给目标服务器,然后将目标服务器的响应转发给客户端。文件,并导入所需的包。

weixin_73725158的博客 893

go实现HTTP3

一、首先什么是HTTP3? 虽然 HTTP/2 解决了很多之前旧版本的问题,但是它还是存在一个巨大的问题,主要是底层支撑的 TCP 协议造成的。 上文提到 HTTP/2 使用了多路复用,一般来说同一域名下只需要使用一个 TCP 连接。但当这个连接中出现了丢包的情况,那就会导致 HTTP/2 的表现情况反倒不如 HTTP/1 了。 因为在出现丢包的情况下,整个 TCP 都要开始等待重传,也就导致了后...

点点的博客 5575

Golang开启http服务

#开启http服务 func HttpService() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // r.FormValue() 获取参数 name := r.FormValue("name") id := r.FormValue("id") status := r.FormV...

懒人程序员的博客 624

GoReq完全指南:为什么这款HTTP请求库能让Go开发效率提升300%?

GoReq是一款为Go语言设计的轻量级HTTP请求库,它以简洁易用的API和强大的功能组合,帮助开发者摆脱原生库的冗长代码,显著提升HTTP请求处理效率。无论是REST API调用、数据抓取还是服务间通信,GoReq都能以最少的代码实现复杂功能,让Go开发变得更简单高效。 ## 为什么选择GoReq?3大核心优势解析 在Go语言中进行HTTP请求时,原生`net/http`库虽然功能强大,但往

gitblog_01195的博客 281

go http

http包提供了HTTP客户端和服务端的实现 *http.Request 获取客户端提交的数据 http.ResponseWriter向客户端响应数据 http_server.go: /* 自定义http的业务逻辑函数 */ // response是一个io.Writer, 相当于一个打开了的文件(浏览器窗口) func login(response http.ResponseW...

lljxk2008的博客 521

res-downloader 资源下载完整教程:开启本地代理到批量保存 m3u8 视频

res-downloader 是一款本地资源下载工具,它在你电脑上起一个代理,把视频号、抖音、m3u8 等流量里的真实媒体文件自动拦下来存成本地文件,替你省掉手动找链接、复制地址、盯链接过期的操作,适合想批量保存视频资源的普通用户。 ## 快速上手:三步让文件落盘 最短路径就是:装好 → 开代理 → 下载。 - **步骤 1|装软件并开代理** - 点首页左上角"开启代理",安装时同意安

gitblog_00338的博客 826

goland http proxy 代理设置

Goland系统设置中设置并且开启了 HTTP Proxy 后,如果Go代码使用 net/http 包进行网络请求,并且通过Goland运行,也会去读取这个 HTTP Proxy环境变量走这代理。

whatday的专栏 3118

调试 sendgrid/rest 发出的 HTTP 请求:在 Go 中查看请求体与完整请求转储

本篇技术指南围绕 [sendgrid/rest](https://link.gitcode.com/i/c401f216bf13981988c74acf3fa9d06f) 的官方故障排查文档展开,讲解如何在不修改业务代码的前提下,拦截并查看即将发出的 REST 请求体(Request Body)与完整的原始 HTTP 请求(Request Dump),用于调试、联调与测试场景。读完本文你将掌握一套

gitblog_00269的博客 131

http2、grpc 的反向代理的实现

grpc 使用的是 http2, 如果要代理 grpc 请求,就需要开启 tls, tls 的生成请参考我以前的博客。看看使用的是不是 http2.Transport, 还有是不是启用的是 https 服务。采用golang 的自带的代理。transport 采用。

wanmei002的博客 977
上一篇: [Golang]快速排序
下一篇: [Pytorch]基于DDP的单机多卡训练
COMEO
博客等级 码龄11年 0粉丝 9原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值