Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT with headers. #17

Open
romibe opened this issue Nov 21, 2018 · 5 comments
Open

PUT with headers. #17

romibe opened this issue Nov 21, 2018 · 5 comments

Comments

@romibe
Copy link

romibe commented Nov 21, 2018

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
Copy link
Owner

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
Copy link
Author

romibe commented Nov 22, 2018

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
Copy link

kennedn commented Oct 14, 2020

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.

xhr.open(method, ToUrl, true);

Should be ran before

// append all the headers in the request
for (var i = 0; i < headers.length; i++) {
for (var key in headers[i]) {
key = key.trim();
val = headers[i][key].trim();
if (key && val) {
console.log("Setting header: " + key + ": " + val);
xhr.setRequestHeader(key, val);
}
if (key.toLowerCase() == "content-type") {
overrideContentType = true;
}
}
}

@abelmatser
Copy link

abelmatser commented Oct 26, 2021

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
Copy link

abelmatser commented Oct 26, 2021

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.

Repository owner deleted a comment from daino0 Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants