# Making requests to https

**URL:** <https://community.haxe.org/t/making-requests-to-https/1983>\
**Category:** Haxe\
**Created:** [August 23, 2019, 9:20am UTC](https://community.haxe.org/t/making-requests-to-https/1983 "2019-08-23T09:20:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaviCervera](https://avatars.discourse-cdn.com/v2/letter/j/65b543/32.png) [@JaviCervera](https://community.haxe.org/u/JaviCervera)\
**Post date:** [August 23, 2019, 9:20am UTC](https://community.haxe.org/t/making-requests-to-https/1983/1 "2019-08-23T09:20:26Z")

</div>

Hello all.

I have searched for similar topics, but I haven’t found an answer that solves my problem. I am trying to make GET requests with https work in Haxe. I have this code:

```haxe
class HttpsTest {
    public static function main() : Void {
        trace(haxe.Http.requestUrl("https://api.github.com"));
    }
}

```

If I run it with `haxe -main HttpsTest --interp`, it gives the error “Https is only supported with -lib hxssl”.

I checked for the hxssl lib, and on [their project page](https://github.com/tong/hxssl) I found this:

> Please note hxssl is depreciated from Haxe 3.3.0 on as it has been merged into Haxe core. This library is no longer maintained, but it will still work for previous versions of Haxe.

I am on Haxe 3.4.7, so according to this hxssl should not be neccesary, but Ok, I have installed it and tried again with `haxe -main HttpsTest -lib hxssl --interp`. Now, the error is “You cannot use the library ‘hxssl’ inside a macro”.

By searching on the web, I found this:

> [@Make https requests from a macro](https://community.haxe.org/t/make-https-requests-from-a-macro/1862):
>
> Hi guys, I am trying to make https requests in a macro but I get the message that I need to use -lib hxssl. Installing this does not work either and the page of hxssl tells me that it is no longer maintained. Is there any advice on how to make a https request. This needs to work both in Windows and a Linux build environment. Thanks!

> <https://github.com/HaxeFoundation/haxe/issues/7619>
>
> I want to download a file from https link within a macro, but I get an error:
> 
> …
> \`\`\`haxe
> Https is only supported with -lib hxssl
> \`\`\`
> I installed \`haxelib install hxssl\` but that has errors:
> \`\`\`
> C:\\HaxeToolkit\\libs\\hxssl/3,0,0-alpha/sys/ssl/Socket.hx:335: characters 10-13 : Type not found : Lib
> C:\\HaxeToolkit\\libs\\hxssl/3,0,0-alpha/sys/ssl/Socket.hx:338: characters 34-37 : Type not found : Lib
> \`\`\`
> 
> I'm using Haxe 4.0.0-preview-5.
> 
> cc @tong : I've added you to this issue since you are original author of the hxssl library, maybe you can help?

It is fine, since I was just using `--interp` for testing purporses. Although it says that support is coming on 4.1, I should be able to use https on other targets on 3.4.7, since the message on the hxssl page says that it is integrated into Haxe since 3.3.0.

So let’s try Python (without hxssl since it’s supposed to not be needed anymore):

```haxe
haxe -main HttpsTest -python output.py

```

When I run the script with Python3, I get an error:

```haxe
Traceback (most recent call last):
  File "output.py", line 1812, in <module>
    HttpsTest.main()
  File "output.py", line 81, in main
    print(str(haxe_Http.requestUrl("https://api.github.com")))
  File "output.py", line 760, in requestUrl
    h.request(False)
  File "output.py", line 306, in request
    self.customRequest(post,output)
  File "output.py", line 323, in customRequest
    raise _HxException("Https is only supported with -lib hxssl")
__main__._HxException: Https is only supported with -lib hxssl

```

So maybe hxssl is not integrated, so I will try by adding it:

```haxe
haxe -main HttpsTest -lib hxssl -python output.py

```

But it looks like hxssl does not compile:

```haxe
/home/javi/haxelib/hxssl/3,0,0-alpha/sys/ssl/Socket.hx:335: characters 9-12 : Type not found : Lib
/home/javi/haxelib/hxssl/3,0,0-alpha/sys/ssl/Socket.hx:334: lines 334-336 : Missing return: Dynamic
/home/javi/haxelib/hxssl/3,0,0-alpha/sys/ssl/Socket.hx:338: characters 33-36 : Type not found : Lib

```

Sorry if I am missing something obvious here, I am very new to Haxe, but this is driving me crazy.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![JaviCervera](https://avatars.discourse-cdn.com/v2/letter/j/65b543/32.png) [@JaviCervera](https://community.haxe.org/u/JaviCervera)\
**Post date:** [August 23, 2019, 9:50am UTC](https://community.haxe.org/t/making-requests-to-https/1983/2 "2019-08-23T09:50:35Z")

</div>

Uhmm this actually seems to be related to Python target. I have tried Java and PHP (without hxssl) and it works on both. Is support for Python target planned? While I can work with PHP now, I actually will need Python in the final version.

---

<div class="post-metadata">

**Author:** ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)\
**Post date:** [September 19, 2019, 2:13pm UTC](https://community.haxe.org/t/making-requests-to-https/1983/3 "2019-09-19T14:13:06Z")

</div>

You can try using tink\_http [GitHub - haxetink/tink\_http: Cross platform HTTP abstraction](https://github.com/haxetink/tink_http)

```haxe
tink.http.Client.fetch('https://api.github.com').all()
  .handle(function(o) switch o {
    case Success(res): trace(res.body.toBytes());
    case Failure(e): trace(e);
  });

```

HTTPS is not supported on eval, but you can make the request through CURL  
`tink.http.Client.fetch('https://api.github.com', {client: Curl})`

---

<div class="post-metadata">

**Author:** ![JaviCervera](https://avatars.discourse-cdn.com/v2/letter/j/65b543/32.png) [@JaviCervera](https://community.haxe.org/u/JaviCervera)\
**Post date:** [September 23, 2019, 2:17pm UTC](https://community.haxe.org/t/making-requests-to-https/1983/4 "2019-09-23T14:17:01Z")

</div>

Thanks for the suggestion, but when compiling to Python it gives me the following error on 3.4.7:

```haxe
/home/javi/haxelib/tink_http/0,8,2/src/tink/http/clients/SocketClient.hx:48: characters 29-49 : Type not found : python.net.SslSocket
/home/javi/haxelib/tink_http/0,8,2/src/tink/http/clients/SocketClient.hx:53: characters 10-30 : sys.net.Socket should be Void
/home/javi/haxelib/tink_http/0,8,2/src/tink/http/clients/SocketClient.hx:61: characters 8-22 : Void has no field connect
/home/javi/haxelib/tink_http/0,8,2/src/tink/http/clients/SocketClient.hx:64: characters 65-78 : Void has no field output
/home/javi/haxelib/tink_http/0,8,2/src/tink/http/clients/SocketClient.hx:65: characters 71-83 : Void has no field input

```

---

<div class="post-metadata">

**Author:** ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)\
**Post date:** [September 23, 2019, 2:31pm UTC](https://community.haxe.org/t/making-requests-to-https/1983/5 "2019-09-23T14:31:05Z")

</div>

You need to use Haxe 4 for SSL support on python target.

---

<div class="post-metadata">

**Author:** ![Wesss](https://avatars.discourse-cdn.com/v2/letter/w/fbc32d/32.png) [@Wesss](https://community.haxe.org/u/Wesss)\
**Post date:** [May 18, 2020, 2:14pm UTC](https://community.haxe.org/t/making-requests-to-https/1983/6 "2020-05-18T14:14:19Z")

</div>

Possible alternative:

```haxe
        var http = new haxe.Http("https://api.github.com");

        http.onData = function (data:String) {
          var result = haxe.Json.parse(data);
          trace(${result});
        }
        
        http.onError = function (error) {
          trace('error: $error');
        }
        
        http.request();

```

see [Loading a file from web - Beginner - Haxe programming language cookbook](https://code.haxe.org/category/beginner/loading-external-files.html)
