Asked  7 Months ago    Answers:  5   Viewed   34 times

I want to make HTTPS request through PHP to a server and get the response.

something similar to this ruby code

  http ="", 443)

  http.use_ssl = true

  path = "uri"

  resp, data = http.get(path, nil)




this might work, give it a shot.

 $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the response and close the channel.
$response = curl_exec($ch);

for more info, check

Wednesday, March 31, 2021
answered 7 Months ago

Problem appears to be specific to PhpStorm as issue can be reproduced on another machine running windows 10


When placing test.php and test2.php into my XAMPP 7.1 localhost directory, the issue does not appear, this also resolves the issue when placing files into WAMP directory on windows 10

Wednesday, March 31, 2021
answered 7 Months ago

Yes this would be a Cross domain posting and would be blocked by the browser.

Thursday, June 24, 2021
answered 4 Months ago

Set the host header for the request:

const https = require('https');

https.get('https://AA.BB.CC.DD', {
  headers : { host : '' }
}, res => {
}).on('error', e => {
  console.log('E', e.message);

EDIT: I dug around a bit to see how this works exactly. To allow HTTPS-based virtual hosting, there's a TLS extension called SNI (Server Name Indication). This extension is used by a client to indicate the hostname to which it is trying to connect, so the server can pick the appropriate certificate that belongs to that hostname.

Node's tls module, which is used by https, has an option servername to set this hostname:

https.get('https://AA.BB.CC.DD', {
  servername :'
}, ...)

However, you still need to pass a Host header too (that's part of the regular HTTP protocol):

https.get('https://AA.BB.CC.DD', {
  headers : { host : '' },
  servername : ''
}, ...)

To keep things DRY, Node.js will set servername to the Host header, unless it's already set to something else (here).

Wednesday, August 11, 2021
answered 3 Months ago

I managed to get it all working asyncronously with both cookies and unsigned https.

I used the code here:

and modified for unsigned https using Brian Yarger's code here:

Self-signed SSL acceptance on Android

(Add the above code to the beginning of run() in

To get the cookies to work, I had to modify some code (POST snippet from

         case POST:
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new StringEntity(data));
            httpPost.addHeader("Cookie", Cookie.getCookie());
            response = httpClient.execute(httpPost);

            Header[] headers=response.getAllHeaders();
            for(int i=0;i<headers.length;i++){

Many thanks to everyone for pointing me in the direction,

Wednesday, September 29, 2021
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :