HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Just starting out? Need help? Post your questions and find answers here.
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post 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.
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by infratec »

ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by ruslanx »

I need with timeout ? ReceiveHTTPMemory has not timeout option ..
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by infratec »

Timeout is only possible with my libcurl.pbi
See Tips 'n Tricks
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post 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
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by ruslanx »

infratec wrote: Sun Feb 12, 2023 2:44 pm 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
hi infratec, I saw your code with winapi : viewtopic.php?p=441105#p441105

can this code be modified for proxy: "ip:port:user:pass" ?
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by infratec »

I don't know. :oops:
I don't use win api any more.
I use only libcurl because it is cross platform.
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post 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 ?
Last edited by ruslanx on Sun Feb 12, 2023 7:39 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by infratec »

Replace

Code: Select all

 curl_easy_setopt(Curl, #CURLOPT_HEADER, 0)
with

Code: Select all

 curl_easy_setopt(Curl, #CURLOPT_HEADER, 1)
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by ruslanx »

no, I need headers of request .. not response

https://mkyong.com/wp-content/uploads/2 ... eaders.png
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post 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.
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post 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 ..
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS - GET HEAD request with proxy like "ip:port:user:pass" ?

Post by infratec »

This code is not useful for me.
I can not run it.
Post Reply