Jump to content

HTTPS request + POST from PHP


Jeroen

Recommended Posts

Hello,

I'm trying to code some module on my Tetra. I want to make a SSL https-request to a server including POST vars. 

But it seems that i cannot do a HttpRequest. I tried to use cURL (not implemented?) and file_get_contents (always FALSE) but still i'm wondering how to to this.

PHP 5.6.17, Python 2.7, Tetra 1.1.1

 

What do i miss, doing wrong or misunderstand??

Link to comment
Share on other sites

Hi Jeroen,

This is how you would send POST data with pure PHP. If you also want to post to HTTPS, you would need to combine it with the following code:

<?php

$context = stream_context_create(["ssl" => ["verify_peer" => true, "cafile" => "/etc/ssl/certs/cacert.pem"]]);
$data = @file_get_contents("https://www.wifipineapple.com/tetra/bulletin", false, $context);

You can see that you need the "ssl" portion for SSL, and that you need "http" part for the POST request and data.

Link to comment
Share on other sites

Thank you, Sebkinne, this worked, i made an error in building the context stream.

But i see you're also using file_get_contents, instead of cURL. I prefer to use cURL because it is a little faster. The script isn't doing much most of the time. It sends real time log entries to another system, the receiver does not accept multiple entries. Especially when starting, it could burst >100 entries instantly, therefore the processing time is more or less relevant. 

Anyway, working fine now; thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Hey Jeroen,

For the record if you want to do HTTP(s) requests with PHP then it's nice and easy to use then Guzzle(http://docs.guzzlephp.org/en/latest/) is a great option, the syntax is easy and it has a nice api which is transport agnostic. Think of it as syntactic sugar.

 

(Also if you're concerned about speed to that level I'd suggest not using PHP and perhaps considering another language)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...