Does `fetch` method support HTTPS?

Hi,

I’m trying to write a login method but it seems that the fetch method don’t support HTTPS protocol. I print the server logs but found no login request.

Yes, what platform are you running on? Do you have a error handler to catch exceptions?

Running on the local preview, added the error handler but also get nothing. When I change the protocol to HTTP and get normal response.

Are you on the slack community? Maybe easier to help you there http://slackcommunity.fusetools.com

@klayer: Is this a public server you can share? Does other HTTPS hosts work?

Sorry, my email can not receive the invite mail…

    console.log('Begin');
    fetch('https://example.com/api/user/login', {
        method: 'POST',
        headers: {
            'Content-type': 'application/json'
        },
        body: JSON.stringify({
            'login_name': userName.value,
            'password': hashedPassword
        })
    })
    .then(function(resp) {
        if (resp.status == 200) {
            console.log('OK');
            return resp.json();
        } else {
            console.log('Network failure: ' + resp.status);
        }
    })
    .then(function(json) {
        console.log('JSON:');
        console.log(JSON.stringify(json));
    })
    .catch(function(err) {
        console.log('Error');
        console.log(JSON.stringify(err));
    });

In the monitor, I got the following messages:

LOG: Begin
LOG: Error
LOG: {"message":"Network request failed"}

And the Nginx server doesn’t receive any request ;(

Can you load other https resources? Can you share the actual URL?

The URL is [https://dp.yiducloud.com.cn/api/user/login](https://dp.yiducloud.com.cn/api/user/login). I haven’t try other https resource.

For me on that url the error handler is thrown:

ERROR: TypeError: Network request failed

    fetch('https://dp.yiducloud.com.cn/api/user/login').then(function (resp) {
        debug_log ("fetch: " + JSON.stringify(resp));
    }).catch(function error (error, e2) {
        debug_log ("ERROR: " + error);
    } );

Strange, I got the following:

LOG: Begin
LOG: OK
LOG: JSON:
LOG: {"message":"登录失败,用户名或者密码错误。","error":true}

Which version of Fuse do you have?

@Anders

it is 0.9.3 (build 5207)

$ fuse --version
Fuse version 0.9.4 (build 5386)
Copyright (C) 2015 Fusetools
$ curl https://dp.yiducloud.com.cn/api/user/login
<html><title>405: Method Not Allowed</title><body>405: Method Not Allowed</body></html>

Oh wait, you both are on OSX right? Then it might be we found an issue with mono :stuck_out_tongue: I will switch to Mac and debug.

OK, I’ll update the latest version and have a try. Thanks guys for helping!

@Anders Yes, I use OSX.

2333333333

Just a quick update. This is a bug that is happening using some certificates. We are still working on the fix for this.

Was the exact cause of this ever identified? I’m on OSX and running into an issue where Fetch doesn’t print anything to the log - not for then() nor for catch(). I’m going to test it on the physical device tomorrow night. My server is using HTTPs. You can check out the certificate https://www.nextplayerup.com

We actually never got to the bottom of it. And other tickets piled up. Tell me how it went on your physical device. If it’s not working I can start digging into it again.

Hi,

there are still some issues with ‘fetch’ using https with username and password. It works for me with iOS, but the same code does not work with neither Android nor Local.

The code:

<App Theme="Basic">
  <JavaScript>
    function test() {
      var username = 'user';
      var password = 'passwd';
      var url = 'https://&#39; + username + ':' + password + '@httpbin.org/basic-auth/user/passwd';
      console.log( "requesting " + url );
      fetch( url ).then( function( response ) {
        console.log( 'status: ' + response.status );
        return response.json();
      } ).then( function( responseObject ) {
        console.log( 'response: ' + JSON.stringify( responseObject ) );
      } ).catch( function( err ) {
          console.log( 'Error: ' + err.message );
      } );
    }
    module.exports = {
      test: test
    }
  </JavaScript>
  <Button Text="Test" Clicked="{test}" />
</App>

Monitor for iOS:

LOG: requesting https://user:passwd@httpbin.org/basic-auth/user/passwd
LOG: status: 200
LOG: response: {"authenticated":true,"user":"user"}

Monitor for Android:

LOG: requesting https://user:passwd@httpbin.org/basic-auth/user/passwd
LOG: status: 401
LOG: Error: Unexpected end of input

Monitor for Local:

LOG: requesting https://user:passwd@httpbin.org/basic-auth/user/passwd
LOG: Error: Network request failed

In a different project with my Apache-Server, I recognized in the access log that Android and Local do not send username and password (as opposed to iOS).

Thanks,

Andreas