victordiaz / PHONK

PHONK is a coding playground for new and old Android devices
https://phonk.app
GNU General Public License v3.0
463 stars 25 forks source link

Add headers to http requests #81

Closed ae3e closed 4 years ago

ae3e commented 4 years ago

I have a web request with basic authentication so I need to had Authorization : header

victordiaz commented 4 years ago

Hi @ae3e Im happy to add the option to add the headers. Could you help me providing a backend code or site where I could test it against?

ae3e commented 4 years ago

Thanks for your quick answer. You could use Posman-echo to test any web requests. More specifically, you can test headers and basic authentication.

victordiaz commented 4 years ago

Thx for pointing me to that service. Superuseful! I had a look already and it's working.

I'll upload tonight a testing version with a more generic HTTP request function :)

ae3e commented 4 years ago

Thanks a lot! I never compiled PHONK by myself so I'll wait for your next release to test it (unless it takes too long... i'll try to compile it! 😉)

victordiaz commented 4 years ago

I will do my best to release a new version tonight, I'll ping you here once done :)

victordiaz commented 4 years ago

Hi @ae3e I uploaded a release here https://github.com/victordiaz/PHONK/releases/tag/1.3.1 You can try the following code

// the concatenation needs a .toString() there is a strange behaviour otherwise
var auth = ('Basic ' + util.stringToBase64('postman:password')).toString()

var req = network.httpRequest({
  method: 'GET',
  url: 'https://postman-echo.com/basic-auth',
  headers: {
    Authorization: auth
  },
}).onResponse(function (e) {
  console.log(e)
})

Let me know if does work for you :)

ae3e commented 4 years ago

Thanks, I just tested it with some home automation devices that need authentication and it works perfectly! You're really doing a great work! 👍