Web Request on local device


#1

1) Give a description of the problem
I have a Rpi on my local network. It runs an application and prints the response. Using a web browser to localIP:port i can see the information on the browser. Have tried using a curl script and getting a response.

When trying to do the web request on webcore using GET, i keep getting a 408 response. Is there something that i am missing here?

Here is a sample of my piston:
18%20pm

This is the log it generated:
33%20pm

This is the curl script that was successfully executed:
17%20pm


#2

Not sure what is causing the 408 timeout, is the hub on the same subnet as your Rpi and computer? Try a closer approximation of the request that the hub performs by adding to the curl:
-H 'Content-Type: text/xml; charset="utf-8"' -A 'Linux UPnP/1.0 SmartThings'


#3

Yup, its connected on the same subnet. Also tried the curl as suggested and the response was as expected.
53%20am

Checked the logs on the IDE and this line showed an error:

error java.lang.NullPointerException: Cannot invoke method tokenize() on null object @line 3168 (localHttpRequestHandler)


#4

Please pardon the dumb question, but shouldnā€™t there be a full path in the request?

When querying my RPi I use either:
Make a GET request to http://IP/folder/filename.ext
-or-
Make a GET request to http://IP:port/folder/filename.ext


#5

Iā€™m using web.py to return results from different applications. So when i enter http://IP:port it will return values from different applications. In this case, a simple text saying ā€œHello Worldā€¦ā€.


#6

I dunnoā€¦ Iā€™ve always used a full path on all my queriesā€¦
(even if the fileā€™s contents changes often)

I am not saying itā€™s impossible, only that I canā€™t recall ever seeing a piston without a full path.
(at least one folder deep)

Trying to determine webCoREā€™s capability, I guess I should probably ask:
Do you have other pistons that can successfully get a response from:
ā€œhttp://IP:portā€
(without a path)
???

If your answer is no, (as is mine), maybe you could test by ā€˜printingā€™ the output to a text based file (such as XML, JSON, TXT etc), and make the webCoRE query using the full path?


#7

The other thought that comes to mind:

There are some OS where a tiny file sits in the root folder and identifies the default action when no ā€œfile.extā€ was selected. Not sure if this applies to your setup thoughā€¦


#8

Ah so that one looks like webCoRE expects the response from the server to have a Content-Type header (which it definitely should for any normal http server) but your curl output does not show a content type header on the response.

In your hello world example, that response coming back from the server should have a header Content-Type: text/plain. Not sure if that is the problem but it does seem to be an issue. The line referenced in the exception is this: def mediaType = hubResponse.getHeaders()['content-type']?.toLowerCase().tokenize(';')[0]


#9

I have some pistons that is able to handle responses without any Content-Type in the Headers. There is an error that is logged but the response is still there.

An observation: when the piston fires, thereā€™s a blue box counting down, I think from around 15 seconds, probably trying to connect.


#10

I tried doing a GET from WC on google.com and there was a response, so iā€™m pretty sure the path is not a mandatory requirement.


#11

Looks like it was something to do with web.py application. Switched to flask and itā€™s now working as intended.

Thanks @WCmore and @ipaterson for looking into this.


#12

Thatā€™s good! Does flask send a content type? It looks like a missing content type would behave differently for remote web requests since that runs through entirely separate code to process the response. If the lack of a content type in the response is common for simple local servers that could explain why some people have had success with opening a public port and accessing the same service from their WAN IP.


#13

Just checked and you may be right. Flask does respond with a content type.

* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 18
< Server: Werkzeug/0.11.15 Python/3.5.3

#14

Iā€™ll see if that can be fixed in webCoRE, I know weā€™ve seen timeouts reported in the past for local requests so it could just be that the responses had no content type.


#15

Having a similar problem with node. The funny thing is Iā€™ve been doing POST statements to the same web service for a year without issue.

Trying to do a GET now and I get a 408 error.

HTTP/1.1 200 OK
X-Powered-By: Express
Date: Tue, 24 Mar 2020 16:05:58 GMT
Connection: keep-alive


#16

I added a content type to my response and that seems to have fixed the issue. Thanks for the clues.