skonagaya / HTTP-Push

HTTP client for Classic Pebble and Pebble Time (Aplite, Basalt, Chalk, Emery, Diorite support). Customize HTTP Request on your phone and trigger the call from your Pebble Watch.
MIT License
23 stars 11 forks source link

PUT with headers. #17

Open romibe opened 5 years ago

romibe commented 5 years ago

Hi, On my Time with 4.4.0 the PUT with Headers does not work (spinning pipe on pebble). Is there any workaround on it? Thx.

PUT https://public-api.nello.io/v1/locations/a71122f1-60ed-46e3-902f-da2e2603c463/open/

Headers: Content-Type: application/json Authorization: Bearer N4atQOdTmbtk3xftsrW3KuLBApI8Be Content-Length: 0

skonagaya commented 5 years ago

I'm not sure if there's enough information to help troubleshoot here.

What's the response that you get back?

Have you tried using a POST instead?

-Sean

romibe commented 5 years ago

Its alive. :) Thank you. There is no response on PUT gET or POST. The pipe on pebble is spinning with no response. I tryed PUT with different agruments - same. Tryed PUT without Headers - response 401. 4.0.0 Android 8.0

I did a workaroud with Tasker and REST plugin, it works.

kennedn commented 4 years ago

Hi, to add context to this issue, I monitored the logs whilst running a PUT request with headers. I get the following;

[10:21:04] pkjs> HTTP Push:150 jskit_system :: PebbleEventListener : bad dispatch on event appmessage: InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.

Looking in at your code this is caused by calling setRequestHeader before xhr.open() has been called, which invalidates the call. https://github.com/skonagaya/HTTP-Push/blob/087d6123876da74467fb860b7d673637562cfd5f/src/js/pebble-js-app.js#L100

Should be ran before

https://github.com/skonagaya/HTTP-Push/blob/087d6123876da74467fb860b7d673637562cfd5f/src/js/pebble-js-app.js#L32-L45

abelmatser commented 3 years ago

To people looking, I believe the issue @kennedn identified is fixed in a fork. Commit linked. I'll try that fork out when I have time and report back. If I forget, bump me ;-)

abelmatser commented 3 years ago

I build the commit and could successfully trigger a Post request to Home Assistant. I used the following self-built .pbw pebble-http-push_clach04.zip or alternatively from a release on my fork.