I'm trying to make a get request from Arduino to GAE using PHP.
Arduino code:
#define DST_IP "https://myservice-183310.appspot.com" // my gae address
String cmd;
Wifi.println("AT+CIPMUX=0");
cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80\r\n";
Wifi.println(cmd);
if(Wifi.find("OK")){
Serial.println("LINK SUCCESS");
}
else{
Serial.println("LINK ERROR");
}
String user_info="GET /register.php?nfc_id=";
user_info+=nfc_id;
user_info+="\r\nHTTP/1.0 HOST: ";
user_info+=DST_IP;
user_info+="\r\n\r\n";
cmd="AT+CIPSEND=";
cmd+=String(user_info.length());
Wifi.println(cmd);
Wifi.print(user_info);
app.yaml in GAE:
runtime: php55
api_version: 1
handlers:
- url: /register.php
script: register.php
And I get a 404 error message, but "https://myservice-183310.appspot.com/register.php?nfc_id=ooo" works in the browser.
Why do I get this error and how can I fix it?
A valid HTTP request should look like:
GET /request.php?nfc_id=MY_NFC_ID HTTP/1.0
Host: myservice-183310.appspot.com
I'm no Arduino coder, but it looks like the request you are sending is:
GET /register.php?nfc_id=MY_NFC_ID
HTTP/1.0 HOST: https://myservice-183310.appspot.com
Things to note
The HTTP/1.0 goes on the same line as the GET, not on its own line.
The Host: HTTP header should not have the protocol https. SSL or non-SSL will already have been handled before these headers can be read, so they are unneeded (and so might only cause trouble).
I think the issue is the "HTTPS" protocol, try with "HTTP".
Related
I have a very simple flask app that is deployed on GKE and exposed via google external load balancer. And getting random 502 responses from the backend-service (added a custom headers on backend-service and nginx to make sure the source and I can see the backend-service's header but not nginx's)
The setup is;
LB -> backend-service -> neg -> pod (nginx -> uwsgi) where pod is the application built using flask and deployed via uwsgi and nginx.
The scenario is to handle image uploads in simple-secured way. Sender sends me a token with upload request.
My flask app
receive request and check the sent token via another service using "requests".
If token valid, proceed to handle the image and return 200
If token is not valid, stop and send back a 401 response.
First, I got suspicious about the 200 and 401's. And reverted all responses to 200. Following some of the expected responses, server starts to respond 502 and keep sending it. "Some of the messages at the very beginning succeeded".
nginx error logs contains below lines
2023/02/08 18:22:29 [error] 10#10: *145 readv() failed (104: Connection reset by peer) while reading upstream, client: 35.191.17.139, server: _, request: "POST /api/v1/imageUpload/image HTTP/1.1", upstream: "uwsgi://127.0.0.1:21270", host: "example-host.com"
my uwsgi.ini file is as below;
[uwsgi]
socket = 127.0.0.1:21270
master
processes = 8
threads = 1
buffer-size = 32768
stats = 127.0.0.1:21290
log-maxsize = 104857600
logdate
log-reopen
log-x-forwarded-for
uid = image_processor
gid = image_processor
need-app
chdir = /server/
wsgi-file = image_processor_application.py
callable = app
py-auto-reload = 1
pidfile = /tmp/uwsgi-imgproc-py.pid
my nginx.conf is as below
location ~ ^/api/ {
client_max_body_size 15M;
include uwsgi_params;
uwsgi_pass 127.0.0.1:21270;
}
Lastly, my app has a healthcheck method with simple JSON response. It does no extra stuff and simply returns. This never fails as explained above.
Edit : my nginx access logs in the pod shows the response as 401 while the client receives 502.
for those who gonna face with the same issue, the problem was post data reading (or not reading).
nginx was expecting to get post data read by the proxied, in our case uwsgi, app. But according to my logic I was not reading it in some cases and returning back the response.
Setting uwsgi post-buffering solved the issue.
post-buffering = %(16 * 1024 * 1024)
Which led me to this solution;
https://stackoverflow.com/a/26765936/631965
Nginx uwsgi (104: Connection reset by peer) while reading response header from upstream
I'm trying to start a simple server in Julia. (Julia 1.7, HTTP v0.9.16, Windows 10).
By copying the snippet in the HTTP docs, I've written
using HTTP
using Sockets
HTTP.serve(Sockets.localhost, 8000) do request::HTTP.Request
#show HTTP.header(request, "Content-Type")
#show HTTP.payload(request)
return HTTP.Response("Helllllo")
end
in a julia terminal.
When i navigate to http://localhost:8000/ in Chrome, it Does show a page with the word "Helllllo".
But, when i try to send GET requests to it, it doesn't answer. Things I tried:
Opening a new julia terminal and writing
using HTTP
r = HTTP.request("GET", "https://127.0.0.1:8000");
What happens is that this command hangs, instead of producing a r.
Going in Chrome console and writing
fetch("https://127.0.0.1:8000")
.then(res => res.json())
.then(console.log)
Again, no answer.
What am I doing wrong?
Thanks!
A couple different issues:
You're trying to read from a https address, after having set up a plain http server. Once you fix this, Julia is able to get a request-response:
julia> r = HTTP.request("GET", "http://127.0.0.1:8000")
HTTP.Messages.Response:
"""
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Helllllo"""
But it still fails in the browser (in Firefox - I assume it will be the same in Chrome) with
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8000/. (Reason: CORS request did not succeed).
This is simply because 127.0.0.1 != localhost for browser, for security purposes (so it doesn't allow you to read from the "different" host at 127.0.0.1 while you're on localhost). If you instead do:
>> fetch("http://localhost:8000")
.then(console.log)
Promise { <state>: "pending" }
Response { type: "basic", url: "http://localhost:8000/", redirected: false, status: 200, ok: true, statusText: "OK", headers: Headers, body: ReadableStream, bodyUsed: false }
I've just started working with the Quectel MC60 and I am having some issues:
About HTTP GET method, I make the following commands:
AT+QIFGCNT=0
AT+QICSGP=1,"my_apn"
AT+QIREGAPP
AT+QIACT
AT+QSSLCFG="https",1
AT+QHTTPURL=39,40
my_url_39_bytes_long
AT+QHTTPGET=60
AT+QHTTPREAD=30
AT+QIDEACT
When using the QCOM software, I make a script running all the above commands sequentially. When it comes to the AT+QHTTPREAD command, the response is always "+CME ERROR: 3822" (HTTP response failed). What can it be? I'm sure the HTTP server is working properly.
The answer is that it is necessary to configure the request header
AT+QIFGCNT=0
AT+QICSGP=1,"my_apn"
AT+QIREGAPP
AT+QIACT
AT+QHTTPURL=39,40
my_url_39_bytes_long
AT+QHTTPCFG="requestheader",1
AT+QHTTPPOST=77
GET path HTTP/1.1
User-Agent: Fiddler
Host: www.my_host.com
AT+QHTTPREAD=30
AT+QIDEACT
NOTE: in AT+HTTPPOST=77, 77 is the size of the POST message (last two \r\n are required and count)
NOTE2: after GET you're supposed to write the path to the url inserted in AT+QHTTPURL. For example, if you specified your URL as https://www.my_host.com/debug/main/port, your AT+HTTPPOST request should look like this (don't forget the last two \r\n):
GET /debug/main/port HTTP/1.1
User-Agent: Fiddler
Host: www.my_host.com
I have developed an OpenLayers web app that uses GeoServer. I am using nginx as my webserver with proxy_pass setup for GeoServer. Everything works as expected when I use "localhost" but when I switch to my IP address I get a 504 Gateway Time-Out error for
http://98.153.141.207/geoserver/cite/wfs.
I can access GeoServer at
http://98.153.141.207/geoserver/web
via a browser without problem so it would appear the proxy continues to work as expected.
The GeoServer log shows this when the problem occurs:
Request: describeFeatureType
service = WFS
version = 1.1.0
baseUrl = http://98.153.141.207:80/geoserver/
typeName[0] = {http://www.opengeospatial.net/cite}MyLayer
outputFormat = text/xml; subtype=gml/3.1.1
Then after a minute, I get the 504 Gateway Time-Out in my JavaScript console and this shows up in the GeoServer log:
09 May 06:02:15 WARN [geotools.xml] - Error parsing: http://98.153.141.207/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=cite:MyLayer
I have tried this supposed problem URL in a browser and it works fine.
The nginx erorr log contains this:
2013/05/09 06:02:15 [error] 420#3844: *54 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 98.153.141.207, server: localhost, request: "GET /geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=cite:MyLayer HTTP/1.1", upstream: "http://127.0.0.1:8080/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=cite:MyLayer", host: "98.153.141.207"
Further investigation reveals that this problem seems to be restrict to WFS layers only. The WMS layers work fine. Here is the declaration of my WFS layer that fails:
myLayer = new OpenLayers.Layer.Vector("MyLayer",
{
strategies: [new OpenLayers.Strategy.BBOX(),saveStrategy],
projection: "EPSG:2276",
protocol: new OpenLayers.Protocol.WFS(
{
version: "1.1.0",
url: "http://" + hostip + "/geoserver/cite/wfs",
featureNS: "http://www.opengeospatial.net/cite",
srsName: "EPSG:2276",
featureType: "MyLayer",
geometryName: "Poly",
schema: "http://" + hostip + "/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=cite:MyLayer"
})
});
Any help would be appreciated. Thanks
I managed to get this working by remove the "schema" property from the OpenLayer.Protocol.WFS of my layer. Can anyone explain why this would be the problem?
i build proxy server and it works great, however there are some sites which he cannot handle.
I tried to reduce the problem to its core and this is what i came up with:
My test case is: http://bits.wikimedia.org/en.wikipedia.org/load.php
which is one of the http messages transfered in each wikipedia page.
So i tried to build a request for it and send it via a socket like this:
String request1 =
"GET http://bits.wikimedia.org/en.wikipedia.org/load.php HTTP/1.1" +
"\r\n" +
"Host: bits.wikimedia.org" + "\r\n" +
"User-Agent: MyHttpProxy/example.java (http://stackoverflow.com/q/5924490/319266)" +
"\r\n" + "\r\n";
However i got 404 return code - which was strange because this page does exist!
I made alot of trys and made a new request which was different only in the request line:
String request2 =
"GET /en.wikipedia.org/load.php HTTP/1.1" +
"\r\n" +
"Host: bits.wikimedia.org" +
"\r\n" +
"User-Agent: MyHttpProxy/example.java (http://stackoverflow.com/q/5924490/319266)" +
"\r\n" + "\r\n";
and it worked! a good 200 was brought back with
some unimportent content("/* No modules requested. Max made me put this here */")
Can anyone tell me what is the problem here?
i looked at the rfc and i couldnt make any reason of this...
Here is the source code for running this test and print the resuls:
You would provide the full URL in the request line only if you're going via a proxy server. Direct requests to a web server need to follow the form as in request2 in your example.
Looking at the source, you send requests to port 80, which almost 100% means they're not going through a proxy. My guess is that you need to send request1 to port 8080 or whatever port your proxy is listening on.
As for the RFC, take a look at section 5.1.2. Note that the absolute path is used with proxies, and relative path with origin servers.