Server responded with 400 Bad Request during HTTP Post request - http-post

I am using SIM800 to send HTTP Post request to a remote InfluxDB database. I have successfully sent HTTP Post request to the database from my computer using Curl as shown below.
01:~$ curl -i -XPOST 'http://<ip address>:8086/write?db=mydb' --data-binary 'location,host=server01,region=us-west value=0.99'
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 3c958273-edb2-11eb-88ca-000000000000
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.6.3
X-Request-Id: 3c958273-edb2-11eb-88ca-000000000000
Date: Mon, 26 Jul 2021 01:38:54 GMT
After that when I tried using SIM800, I received 400 Bad Request after executing AT+HTTPACTION=1 . The remote server responded with "+HTTPACTION: 1,400,0" . Below are the AT Commands.
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","myAPN"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://<ip address>:8086/write?db=mydb"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPPARA="USERDATA","location,host=server01,region=us-west value=0.55"
AT+HTTPDATA=300,5000
AT+HTTPACTION=1
AT+HTTPREAD
AT+HTTPTERM
AT+SAPBR=0,1
Besides that, i captured the packets when SIM800 sent http post request but could not find the http post body.
The http post body can be seen in the captured packets when sending http post using Curl.
I appreciate if anyone can shed some light on this matter. Thank you in advance.

I managed to get it to work. Here are the AT commands:-
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","myAPN"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://<ip address>:8086/write?db=mydb"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=48,5000
location,host=server01,region=us-west value=0.55
AT+HTTPACTION=1
AT+HTTPREAD
AT+HTTPTERM
AT+SAPBR=0,1
after executing the AT+HTTPDATA, quickly execute the HTTP data (location,host...).

Related

Spatie/Laravel cors issue in production [duplicate]

This question already has answers here:
How to resolve 'preflight is invalid (redirect)' or 'redirect is not allowed for a preflight request'
(6 answers)
Closed 1 year ago.
This cors issue will be the death of me. Anyways I am trying to trouble shoot why the spatie/cors package works locally but does not in production. If anybody has experience with this I would appreciate the help!! I am trying to access my backend but getting an alarm saying
my url has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request
Your URL https://aewcpa.traxit.pro/api/account is returning a 301 redirect to https://traxit.pro/api/account for the CORS OPTIONS request, which is causing this issue.
You can see this in action in your browser's network console, or with cURL:
curl -I 'https://aewcpa.traxit.pro/api/account' -X OPTIONS -H 'Access-Control-Request-Method: GET' -H 'Referer: https://aewcpa.traxit.io/login' -H 'Origin: https://aewcpa.traxit.io'
HTTP/2 301
server: nginx/1.15.6
date: Fri, 21 Dec 2018 18:14:36 GMT
content-type: text/html
content-length: 169
location: https://traxit.pro/api/account

H2O Import files via REST API from local server fails

I am trying to use h2o REST API to import CSV files that I have on my local server.
Command:
curl -v -X GET
'http://127.0.0.1:54321/3/ImportFiles?path=http://127.0.0.1:8083/datasets/tables/csv/RDsTWgcvAjHeWJFnbhCKTCE5rn6aLCjJ.csv'
Result in following log:
Trying 127.0.0.1... Connected to 127.0.0.1 (127.0.0.1) port 54321 (#0)
GET
/3/ImportFiles?path=http://127.0.0.1:8083/datasets/tables/csv/RDsTWgcvAjHeWJFnbhCKTCE5rn6aLCjJ.csv HTTP/1.1 Host: 127.0.0.1:54321 User-Agent: curl/7.47.0 Accept: /
HTTP/1.1 200 OK X-h2o-build-project-version: 3.16.0.2
X-h2o-rest-api-version-max: 3 X-h2o-cluster-id: 1512722051559
X-h2o-cluster-good: true X-h2o-context-path: / Content-Type:
application/json Content-Length: 349 Server: Jetty(8.y.z-SNAPSHOT)
Connection #0 to host 127.0.0.1 left intact
{"__meta":{"schema_version":3,"schema_name":"ImportFilesV3","schema_type":"ImportFiles"},"_exclude_fields":"","path":"http://127.0.0.1:8083/datasets/tables/csv/RDsTWgcvAjHeWJFnbhCKTCE5rn6aLCjJ.csv","pattern":null,"files":[],"destination_frames":[],"fails":["http://127.0.0.1:8083/datasets/tables/csv/RDsTWgcvAjHeWJFnbhCKTCE5rn6aLCjJ.csv"],"dels":[]}
H2O log on TRACE level shows only:
12-08 15:41:59.951 10.8.128.101:54321 36013 #4756-331 INFO: GET
/3/ImportFiles, parms:
{path=http://127.0.0.1:8083/datasets/tables/csv/RDsTWgcvAjHeWJFnbhCKTCE5rn6aLCjJ.csv}
Is there any way to debug while importing fails? h2o does not asking local server at all.
Commands from other servers work well:
curl -v -X GET "http://127.0.0.1:54321/3/ImportFiles?path=http://s3.amazonaws.com/h2o-public-test-data/smalldata/flow_examples/arrhythmia.csv.gz"
curl -v -X GET "https://raw.github.com/h2oai/h2o/master/smalldata/logreg/prostate.csv"
In general, trying to interact directly with the H2O REST API isn't easy. The vast majority of people use a pre-made API client like Python or R.
But if you really want to do this, I would debug it by comparing with something that's working. Like the R client for H2O.
Write an R program that does this:
h2o.init()
h2o.startLogging()
h2o.importFile("/path/to/data.csv")
The startLogging() call will produce a detailed log file with all the REST API requests and responses. Look at that and try to mimic it.
You can also refer to the autogenerated REST API documentation (http://docs.h2o.ai/h2o/latest-stable/h2o-docs/rest-api-reference.html), but I would caution that if you tried to write a working client just based on the docs it would be hard.
Looking at a logged conversation from an already working client is by far your best bet.
library(h2o)
h2o.init()
h2o.startLogging()
h2o.importFile("http://localhost:8082/datasets/tables/csv/vPrzC5TOQr6JTvnAYrU5AKyz8SP4ao8p.csv")
Time: 2017-12-11 11:55:09.237
GET http://localhost:54321/3/Cloud?skip_ticks=true postBody:
curlError: FALSE curlErrorMessage: httpStatusCode: 200
httpStatusMessage: OK millis: 7
{"__meta":{"schema_version":3,"schema_name":"CloudV3","schema_type":"Iced"},"_exclude_fields":"","skip_ticks":true,"version":"3.16.0.2","branch_name":"rel-wheeler","build_number":"2","build_age":"10 days","build_too_old":false,"node_idx":0,"cloud_name":"H2O_started_from_R_vasiliy_gey658","cloud_size":1,"cloud_uptime_millis":306486,"cloud_healthy":true,"bad_nodes":0,"consensus":true,"locked":true,"is_client":false,"nodes":[{"__meta":{"schema_version":3,"schema_name":"NodeV3","schema_type":"Iced"},"h2o":"localhost/127.0.0.1:54321","ip_port":"127.0.0.1:54321","healthy":true,"last_ping":1512982506643,"pid":97891,"num_cpus":4,"cpus_allowed":4,"nthreads":4,"sys_load":2.0917969,"my_cpu_pct":-1,"sys_cpu_pct":-1,"mem_value_size":17408,"pojo_mem":12224512,"free_mem":1896688640,"max_mem":1908930560,"swap_mem":0,"num_keys":56,"free_disk":0,"max_disk":0,"rpcs_active":0,"fjthrds":[-1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,-1,1,0,0,0,0,0,0,0],"fjqueue":[-1,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,0,0,0,0,0,0,0],"tcps_active":0,"open_fds":-1,"gflops":4.598999977111816,"mem_bw":6.423728128E9}],"internal_security_enabled":false}
Time: 2017-12-11 11:55:09.251
GET
http://localhost:54321/3/ImportFiles?path=http%3A%2F%2Flocalhost%3A8082%2Fdatasets%2Ftables%2Fcsv%2FvPrzC5TOQr6JTvnAYrU5AKyz8SP4ao8p.csv&pattern=
postBody:
curlError: FALSE curlErrorMessage: httpStatusCode: 200
httpStatusMessage: OK millis: 6
{"__meta":{"schema_version":3,"schema_name":"ImportFilesV3","schema_type":"ImportFiles"},"_exclude_fields":"","path":"http://localhost:8082/datasets/tables/csv/vPrzC5TOQr6JTvnAYrU5AKyz8SP4ao8p.csv","pattern":"","files":[],"destination_frames":[],"fails":["http://localhost:8082/datasets/tables/csv/vPrzC5TOQr6JTvnAYrU5AKyz8SP4ao8p.csv"],"dels":[]}
This is my import information.

How to subscribe to the PubSubHubbub github?

I'm currently attempting to write a basic client that listens to events from (enterprise) github, and makes API calls accordingly.
The problem I have is that I can't manage to get the PubSubHubbub client configured. I thought it was the client/authentication I'm using, but I now can't get the basic call from the docs working!
In an attempt to work out what I'm doing wrong, I'm making a curl request to my normal github account:
curl -u "joepym" -i \
https://api.github.com/hub \
-F "hub.mode=subscribe" \
-F "hub.topic=http://github.com/JoePym/faraday/events/push" \
-F "hub.callback=*callbackurl*"
and I'm getting back
HTTP/1.1 100 Continue
HTTP/1.1 422 Unprocessable Entity
Server: GitHub.com
Date: Wed, 08 May 2013 18:13:24 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 422 Unprocessable Entity
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4989
X-GitHub-Media-Type: github.beta
X-Content-Type-Options: nosniff
Content-Length: 38
{
"message": "Invalid event: nil"
}
This invalid event message is what my main client is also getting when I attempt to call my enterprise github account with enterprise credentials.
Has anyone encountered this before?
Try using https://github.com/JoePym/faraday/events/push as your hub.topic. Note that we are now using 'https'.

my https website can't download by WGET command

I can browse the page by browser, but I can't download the html page by wget.
https://money.benck.tw
When I use wget, it can't even connect to the website:
--2011-10-12 05:30:24-- https://money.benck.tw/
Resolving money.benck.tw... 97.107.135.68
Connecting to money.benck.tw|97.107.135.68|:443... failed: Connection timed out.
Retrying.
--2011-10-12 05:33:35-- (try: 2) https://money.benck.tw/
Connecting to money.benck.tw|97.107.135.68|:443...
However, I can download the other https website like: https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
It's very weird.
For this website you have to use the --no-check-certificate command
wget --no-check-certificate https://money.benck.tw
I'm experiments the same issue, I trying to download files from an external site like https://downloads.wordpress.org/plugin/easy-wp-smtp.zip and I wget using --no-check-certificate stills not working.... It's freezing in this line:
Connecting to downloads.wordpress.org (downloads.wordpress.org)|198.143.164.250|:443...
Anyone have the same issue?
No IP tables configured and rules. When I do this on other server on the same networks works fine. This only happens on this server specialy.
Regards,
Francisco Yu
This is because of this page is probably scraped by wget too often. You need to modify headers, especially useragent.
Examples from other website:
--no-check-certificate does not hepls
wget --no-check-certificate "https://www.money.pl/pieniadze/depozyty/walutowearch/1921-02-05,2021-02-05,LIBORCHF3M,strona,1.html" --2021-02-05 17:05:34-- https://www.money.pl/pieniadze/depozyty/walutowearch/1921-02-05,2021-02-05,LIBORCHF3M,strona,1.html
Loaded CA certificate '/etc/ssl/certs/ca-certificates.crt'
Resolving www.money.pl (www.money.pl)... 212.77.101.20
Connecting to www.money.pl (www.money.pl)|212.77.101.20|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2021-02-05 17:05:34 ERROR 403: Forbidden.
but other tool to download sendign other headers works
http -h "https://www.money.pl/pieniadze/depozyty/walutowearch/1921-02-05,2021-02-05,LIBORCHF3M,strona,1.html"
HTTP/1.1 200 OK
Cache-control: max-age=60, public,stale-while-revalidate=5
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 20756
Content-Security-Policy: upgrade-insecure-requests;
Content-Type: text/html; charset=iso-8859-2
Date: Fri, 05 Feb 2021 16:04:16 GMT
Link: <https://money.wp.pl/dGxwOTV0SyYZFTlneUtGM1pNbSY9EkhlJ1V1dglvOxgnKBALCW87GCcoEAsJbzsYJygQCwlvOxgnKBALCW87GCcoEAsJbzsYJygQCwlvOxgnKBALCW87GCcoEAsJbzsYJygQCwlvOxgnKBALCW87GCcoEAsJbzsYJygQCwlvOxgnKBALCW87GCcobXh0RUZ9WlgoNTAeDjRHBTlpZxYWIhMeKydrAld1TER2ciZYECoUSjgjIR4JKBYSNnomXEF1TUUJJD9VCi4ZEzUxcwJRdT4TKiQ5Sh0zAVJ9YWR2EyYUAjs7IVUFNRsfamZjAiJ2QUV-eWYCSXdNUn1hZHNWd0pGYmRkHVRyXUV6ZhV8LQU3JQwcEAMpYkpCfRclRBYoFhZqZmMCJ3ZWHzs5OhY0EDkoLjA0VFl1XgQ_PTgNKRMbQgIuB0lCIRQEOzUiWQB6XhYrIgVcCzMLSn9lZhYHJBkDKjM5Qh16DxYjISJJRjo=>;rel="preload";as="script";
Server: nginx
Set-Cookie: mny_ver2=v8c;Domain=.money.pl;Path=/;Max-Age=2592000;
Vary: Accept-Encoding

HTTP server with Ruby

I am trying to make a small HTTP server in Ruby. Its just meant to learn how stuff works, nothing big. So what i did is to send the server an ajax request. The server is listening on port 2000, and so the ajax request is also on port 2000.
The problem i am facing is that the ajax request is returned only with the headers, the content is missing. I tried everything i could find, but it seems to fail too...
I have attached the code, for you to take a look
require 'socket' # Get sockets from stdlib
server = TCPServer.new(2000) # Socket to listen on port 2000
loop { # Servers run forever
client = server.accept # Wait for a client to connect
headers = "HTTP/1.1 200 OK\r\nDate: Tue, 14 Dec 2010 10:48:45 GMT\r\nServer: Ruby\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n"
client.puts headers # Send the time to the client
client.puts "<html>amit</html>"
client.close # Disconnect from the client
}
The ajax request is working when pointed to a PHP script running on Apache. the only problem seems to occur when using this server.
Any help is as always, deeply appreciated :)
Regards,
Amit
Your code works fine.
$ telnet localhost 2000
HTTP/1.1 200 OK
Date: Tue, 14 Dec 2010 10:48:45 GMT
Server: Ruby
Content-Type: text/html; charset=iso-8859-1
<html>amit</html>
Connection to host lost.
Now you'll have to find out what's wrong with your AJAX request...
I also included the Content-Length header and that seemed to clear up the errors I was getting with curl:
require 'socket' # Get sockets from stdlib
server = TCPServer.new(2000) # Socket to listen on port 2000
loop { # Servers run forever
client = server.accept # Wait for a client to connect
resp = "<html>amit</html>"
headers = ["HTTP/1.1 200 OK",
"Date: Tue, 14 Dec 2010 10:48:45 GMT",
"Server: Ruby",
"Content-Type: text/html; charset=iso-8859-1",
"Content-Length: #{resp.length}\r\n\r\n"].join("\r\n")
client.puts headers # Send the time to the client
client.puts resp
client.close # Disconnect from the client
}
You're missing the Access-Control-Allow-Origin HTTP header in your response headers.
Since you're trying an AJAX request, and it is basically an XHTTPRequest, you need to pass it in the response to the client, in order to accomplish the Cross-Origin Resource Sharing implementations of your browser.
Just add in your HTTP server:
headers = "HTTP/1.1 200 OK\r\n"
headers += "Access-Control-Allow-Origin: *\r\n"
headers += "Date: Tue, 14 Dec 2010 10:48:45 GMT\r\nServer: Ruby\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n"
and then you can try to see if works.

Resources