Page 1 of 1
HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 2:21 pm
by ruslanx
Hi, I need to make request HTTPS - GET or HEAD .. to test my server or ping ... but only through proxy with authentication .. can someone help with code .. winApi or else ? thank you.
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 2:26 pm
by infratec
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 2:32 pm
by ruslanx
I need with timeout ? ReceiveHTTPMemory has not timeout option ..
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 2:39 pm
by infratec
Timeout is only possible with my libcurl.pbi
See Tips 'n Tricks
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 2:44 pm
by infratec
Since I have no proxy with user and password, I can not provide a working example
Usage see here:
https://curl.se/libcurl/c/CURLOPT_PROXYUSERPWD.html
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 3:18 pm
by ruslanx
hi
infratec, I saw your code with winapi :
viewtopic.php?p=441105#p441105
can this code be modified for proxy: "ip:port:user:pass" ?
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 3:27 pm
by infratec
I don't know.
I don't use win api any more.
I use only libcurl because it is cross platform.
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 6:46 pm
by ruslanx
Thank you
infratec, I get it working...
Code: Select all
IncludeFile "LibCurl.pbi"
Procedure.s URLGetData(URL$)
Protected Curl.i, *CurlSList, Response$, ret.l, total_time.d, connect.d
Curl = curl_easy_init()
If Curl
*CurlSList = curl_slist_append(#Null, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36")
curl_easy_setopt(Curl, #CURLOPT_HTTPHEADER, *CurlSList)
curl_easy_setopt_str(Curl, #CURLOPT_URL, URL$)
curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 0)
curl_easy_setopt_str(Curl, #CURLOPT_PROXY, "http://proxyIP:proxyPort")
curl_easy_setopt_str(Curl, #CURLOPT_PROXYUSERPWD, "proxyUser:proxyPass")
curl_easy_setopt(Curl, #CURLOPT_NOBODY, 1)
curl_easy_setopt(Curl, #CURLOPT_HEADER, 0)
curl_easy_setopt(Curl, #CURLOPT_NOPROGRESS, 1)
curl_easy_setopt(Curl, #CURLOPT_TIMEOUT_MS, 1000)
curl_easy_setopt(Curl, #CURLOPT_TCP_KEEPALIVE, 0)
; accept insecure certificates
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False)
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False)
; use own receive function
;curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @LibCurl_WriteFunction())
If curl_easy_perform(Curl) = #CURLE_OK
Debug "Ok"
curl_easy_getinfo(Curl, #CURLINFO_TOTAL_TIME, @total_time)
curl_easy_getinfo(Curl, #CURLINFO_PRETRANSFER_TIME, @connect)
;Response$ = LibCurl_GetData()
Debug StrD(total_time * 1000, 1) + " ms -- " + StrD(connect * 1000, 1) + " ms"
Else
Debug "Error: " + curl_easy_strerror(res)
EndIf
curl_slist_free_all(*CurlSList)
curl_easy_cleanup(Curl)
EndIf
ProcedureReturn Response$
EndProcedure
Debug URLGetData("https://google.com")
> How can I see all request headers .. I need to see what is send, what headers ?
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 6:51 pm
by infratec
Replace
Code: Select all
curl_easy_setopt(Curl, #CURLOPT_HEADER, 0)
with
Code: Select all
curl_easy_setopt(Curl, #CURLOPT_HEADER, 1)
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 7:19 pm
by ruslanx
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 8:19 pm
by infratec
You build the header of the request.
So you should know what is inside (header slist)
I don't know which header you want to see.
Your link looks líke the response page from a website and not like header lines.
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 10:03 pm
by ruslanx
Code: Select all
import socket
HOST = "127.0.0.1"
PORT = 65431
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
while True:
conn, addr = s.accept()
with conn:
print(f"connected by {addr}")
data = conn.recv(1024)
print(data.decode())
conn.send(data)
conn.close()
a small code to show real headers ..
Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?
Posted: Sun Feb 12, 2023 10:05 pm
by infratec
This code is not useful for me.
I can not run it.