Sending POST request to HTTPS clould function by using sim 800l module - esp32

hiii, This is for Sending HTTPS POST request to clould function server by using sim800l gprs module.the main problem is its could not send the data to server but its connects the server and its shows bad request 400.I can't understand the problem.the code will be given below.i use NODEMCU-32S micro controller.
SerialMon.println("Performing HTTP POST request...");
String httpRequestData = String(requestBody) +"";
client.print(String("POST ") + resource + " HTTP/1.1\r\n");
client.print(String("Host: ") + server + "\r\n");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(httpRequestData.length());
client.println();
client.println(httpRequestData);
timeout = millis();
while (client.connected() && millis() - timeout < 10000L) {
while (client.available()) {
char c = client.read();
SerialMon.print(c);
timeout = millis();
}
}
enter image description here <--this is the output image.
please help me to find out the solution.

This is happening because of cloudflare protection on server's end.
Things you can try
Download Cloudflare SSL from your account in your system before doing request
Disable cloudflare end to end SSL verification
Make request from https to https via connecting your Esp32 to a static IP

Related

Is it possible to setup CORS Anywhere on localhost?

I am building a web scraper as a small project (using CodeIgniter). Due to CORS policy, I am not allowed to get data from some sites.
To bypass that, I am using Rob Wu's CORS Anywhere. I'm prepending the cors_url to the URL I'm scraping data off of.
Everything works fine until I hit the maximum allowed limit of 200 requests per hour. After hitting 200 times, I get an HTTP status code: 429 (Too many requests).
Screenshot showing Network log.
As per the documentation, we can create an instance of our own server.js on Heroku. But, what I want to do is, to set it up locally for my local Apache server (localhost), just to test out the things first.
Some sample code:
var url = "http://example.com/";
var cors_url = "https://cors-anywhere.herokuapp.com/";
$.ajax({
method:'GET',
url : cors_url + url,
success : function(response){
//data_scraping_logic...
}
}
Install the latest node
save the repo example code as cors.js (I'll paste it below)
do npm install cors-anywhere
run node cors - now it's running on localhost:8080
sample code
// Listen on a specific host via the HOST environment variable
var host = process.env.HOST || '0.0.0.0';
// Listen on a specific port via the PORT environment variable
var port = process.env.PORT || 8080;
var cors_proxy = require('cors-anywhere');
cors_proxy.createServer({
originWhitelist: [], // Allow all origins
// requireHeader: ['origin', 'x-requested-with'],
// removeHeaders: ['cookie', 'cookie2']
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
});

413 Request Entity Too Large For HttpClient

Once i send the HttpClient request through the PostAsJsonAsync i get the response as Request Entity too large. but i can directly call to webapi and send the request and returns a successfull response. but through the PostAsJsonAsync it returns the 413 error code.
This is my code
var client = new HttpClient { BaseAddress = new Uri(ConfigurationManager.AppSettings.Get("API_HOST")) };
const string api = "CmSaveChange" + "/" + "SaveChange";
var response = client.PostAsJsonAsync(api, entity).Result;
var retunValue = response.Content.ReadAsAsync<HybridDictionary>().Result;
The problem has to be solved on the server-side (self hosting HttpSelfHostServer or IIS).
The buffers have to be set to a higher value.
If the host run's under IIS:
Configure IIS
If the server is running as HttpSelfHostServer:
You have to set higher values (as needed) to the config parameters.
Example for vb.net
Dim cSelhostConfiguration As String = cIPADressePort
' Note: cIPADressePort contains the IP address and port on which the host is listen
Dim config As New HttpSelfHostConfiguration(cSelhostConfiguration)
'Set here the needed size (in bytes)
config.MaxBufferSize = 250000000
config.MaxReceivedMessageSize = 250000000
'
config.Routes.MapHttpRoute(
name:="DefaultApi",
routeTemplate:="api/{controller}/{id}",
defaults:=New With {.id = RouteParameter.Optional}
)
'
Using server As New HttpSelfHostServer(config)
Try
server.OpenAsync().Wait()
Console.WriteLine("")
Console.WriteLine("WebService started... ")
Console.WriteLine("Waiting for work...")
Catch aggEx As AggregateException
Console.WriteLine("Error loading Server")
End Try
Console.WriteLine()
Console.WriteLine("Press enter to close the server")
Console.ReadLine()
End Using

Ruby: Make a call from browser using Twilio

I want to call from my browser to customer phone number using Twilio. I am using toturial of Twilio. I have already an account that I am using for sending sms to my users. Now I want to make phone calls too. This is the code that I am using at my controller
account_sid = "My Twilio account SID"
auth_token = "My Twilio auth"
sender = "My Twilio from number"
capability = Twilio::Util::Capability.new account_sid, auth_token
capability.allow_client_outgoing "My Twilio Twiml app sid"
#capability.allow_client_incoming "jenny"
#token = capability.generate
And this is the javascript code
Twilio.Device.setup("<%= #token %>", {debug: true});
Twilio.Device.ready(function (device) {
$("#log").text("Ready");
});
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
Twilio.Device.connect(function (conn) {
$("#log").text("Successfully established call");
});
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
Twilio.Device.incoming(function (conn) {
$("#log").text("Incoming connection from " + conn.parameters.From);
// accept the incoming connection and start two-way audio
conn.accept();
});
function call() {
// get the phone number to connect the call to
params = {"PhoneNumber": $("#number").val()};
Twilio.Device.connect(params);
}
function hangup() {
Twilio.Device.disconnectAll();
}
But when I try to load my page, it gives me Error: No valid account. I have double checked my credentials and same credentials are successfully sending sms but here it is creating problem. Can any one guide me what Am I doing wrong?
I am doing it on localhost
Megan from Twilio here. You mention you're on localhost. You would need to make your URL publicly accessible. If you're not ready for production, testing with something like Ngrok will allow you to tunnel your localhost to a publicly available URL.

Chrome extension - redirecting an https AJAX request to the same url in onBeforeRequest

I am redirecting every request to the same url in onBeforeRequest listener using redirectUrl directive. It works fine with all sites as Chrome eventually send the request to the url. But I am loosing an AJAX request for one site (the request is not sent at all, e.g. https://apiv2.abc.com/me?token=fiYoEdDLZxPJ...). If I replace return {redirectUrl: request.url}; with just return, everything is fine. Can I redirect every request to itself as the following? I tried this with and without requestHeaders permission. Your suggestions are needed please.
chrome.webRequest.onBeforeRequest.addListener(
function interceptRequest(request) {
if (request.tabId === -1) return;
console.log("In before request: " + request.requestId + ", URL: " + request.url);
return {redirectUrl: request.url};
}, {urls: ['*://*/*']}, ['blocking']);

How to use secure websockets with sock js

I am using SockJS-client. SockJS constructor takes a relative URL as
var ws= new SockJS('/spring-websocket-test/sockjs/echo', undefined,{protocols_whitelist: [transport]});
Where do we indicate that WSS:// be used instead of WS://. If I try absolute URL, it gives error :
XMLHttpRequest cannot load ws://localhost:8080/appname/app. Cross origin requests are only supported for HTTP.
_ws_onclose. wasClean: false code: 1002 reason: Can't connect to server
Not sure why getting this error. Any similar configuration needed on Spring Server Implementation?
Went through the sock JS client code :I went through the client code -sock JS takes care of it -if its HTTPS it uses WSS else it does WS
var that = this;
var url = trans_url + '/websocket';
if (url.slice(0, 5) === 'https') {
url = 'wss' + url.slice(5);
} else {
url = 'ws' + url.slice(4);
}
No need to pass WS or WSS (In fact not even HTTP/HTTPS) with the SockJS constructor -just relative URL is sufficient. SockJs client library takes care of it.
One more surprising fact I encountered, it appends "/websocket" at end of the URL -this gave me clue why I was not able to connect with java client using jetty websocket-client apis
Try this code.
var ws= new SockJS('http://localhost:8080/sockjs/echo', undefined,{protocols_whitelist: [transport]});

Resources