Announcement

Collapse
No announcement yet.

PBH-101 HTTPS Request

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBH-101 HTTPS Request

    Hi,

    how can I perform an HTTPS POST or GET-Request to a given endpoint with the PBH-101 in order to transmit data securely?

  • #2
    Hi there.

    I think you can refer to the example below where PBH-101 performs a HTTPS GET request:

    task0.php
    PHP Code:
    <?php

    if(_SERVER("REQUEST_METHOD"))
    exit; 
    // avoid php execution via http request

    include_once "/lib/sn_dns.php";

    echo 
    "PHPoC example : get web page from https server\r\n";

    $host_name "example.phpoc.com";
    $host_port 443;

    $host_addr dns_lookup($host_nameRR_A);

    if(
    $host_addr == $host_name)
    exit 
    "$host_name : Not Found\r\n";

    $tcp0_pid pid_open("/mmap/tcp0");
    pid_bind($tcp0_pid""0);
    pid_ioctl($tcp0_pid"set api ssl");
    pid_ioctl($tcp0_pid"set ssl method tls1_client");

    echo 
    "connect to $host_addr:$host_port...";

    pid_connect($tcp0_pid$host_addr$host_port);

    do
    $state pid_ioctl($tcp0_pid"get state");
    while((
    $state != SSL_CLOSED) && ($state != SSL_CONNECTED));


    echo 
    "connected\r\n";

    //$http_req = "GET /request_method/ HTTP/1.1\r\n";
    //$http_req = "GET /request_header/ HTTP/1.1\r\n";
    //$http_req = "GET /asciilogo.txt HTTP/1.1\r\n";
    $http_req "GET / HTTP/1.1\r\n";
    $http_req .= "Host: $host_name\r\n";
    $http_req .= "Connection: closed\r\n";
    $http_req .= "\r\n\r\n";

    pid_send($tcp0_pid$http_req);

    $rbuf "";

    for(;;)
    {
    if(
    pid_recv($tcp0_pid$rbuf) > 0)
    {
    echo 
    $rbuf;
    continue;
    }

    if(
    pid_ioctl($tcp0_pid"get state") == SSL_CLOSED)
    break;
    }

    echo 
    "\r\nconnection closed\r\n";

    pid_close($tcp0_pid);

    ?>
    Also don't forget to include sn_dns library .
    https://github.com/phpoc/phpoc-psp/b...lib/sn_dns.php

    Cheers
    Last edited by Homer; 08-18-2020, 01:54 PM.

    Comment

    Working...
    X