API Response: NET_HTTP_REQUEST_TIMEDOUT 100 - api

at first, sorry for my english. :)
In my home-network (with IIS), i have a API at the address: http://pcname:8089.
Then i have programmed a MAUI-App (Blazor) for Android and published it to my SAMSUNG S21.
Now i have the following effects:
PC: Chrome-Browser (http://pcname:8089/api/Sets) --> OK (received all Sets)
PC: VS 2022 Android-Emulator (Pixel 5), my MAUI-App --> OK (received all Sets)
S21: Chrome-Browser (http://pcname:8089/api/Sets) --> OK (received all Sets)
S21: my MAUI-App --> FAILURE ("NET_HTTP_REQUEST_TIMEDOUT 100")
My code in the MAUI-App:
private async Task LoadFromApi()
{
HttpClient _client = new HttpClient();
try
{
var response = await _client.GetAsync("http://pcname:8089/api/Sets");
[..]
}
catch(Exception ex)
{
[..]
}
}
Has anyone an idea why my code runs at VS 2022 Emulator but not at my SAMSUNG S21?
Thanks very much!

Related

Sending POST Json to API using Arduino Mega and Ethernet shield W5100

Having this as my sketch, the serial monitor saying that the JSON is successfully sent. But it does not reflect to my Cloud DB.
I changed my HTTPS to HTTP but no luck. Where could this go wrong?
My objective is all input in my Arduino will be sent to my server and store to my Cloud DB.
EDIT: After replacing all suggested Edits, I am getting 400 Bad request.
In Postman, the request is working so i know that my request is valid. But I can't make it work in arduino using ethernet shield
void setup() {
Serial.begin(9600);
// initialize the Ethernet shield using DHCP:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to obtaining an IP address using DHCP");
while(true);
}
delay(1000);
Serial.println("connecting...");
if (client.connect(HOST_NAME, HTTP_PORT)) {
Serial.println("connected");
} else {
Serial.println("connection failed");
}
//Create JSON doc and write a "name" attribute
const size_t capacity = JSON_OBJECT_SIZE(3);
DynamicJsonDocument doc(capacity);
doc["tank_id"] = "2a";
doc["branch_name"] = "aurora";
doc["water_level"] = "high level";
//POST request
Serial.println("Begin POST Request");
client.println("POST /myURL HTTP/1.1");
Serial.println("POST /myURL HTTP/1.1");
client.println("Host: host.net");
Serial.println("Host: host.net");
client.println("User-Agent: Arduino/1.0");
Serial.println("User-Agent: Arduino/1.0");
client.println("Content-Type: application/json");
Serial.println("Content-Type: application/json");
client.println("Connection: keep-alive");
Serial.println("Connection: keep-alive");
client.print("Content-Length: ");
Serial.print("Content-Length: ");
client.println(measureJson(doc));
Serial.println(measureJson(doc));
client.println();
Serial.print(F("Sending: "));
serializeJson(doc, Serial);
Serial.println();
//This works like client.println, but prints doc to client
serializeJsonPretty(doc, client);
//To let me know that request has been completed
Serial.println("Sent POST Request");
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
void loop() {
while(client.connected()) {
if(client.available()){
// read an incoming byte from the server and print it to serial monitor:
char c = client.read();
Serial.print(c);
}
}
}
I had exactly the same issue... after hours and hours of trying different codes, I found the problem:
serializeJsonPretty(doc, client);
This code, prints this:
POST /api/ HTTP/1.1
Host: api.xxxxxxx.com
Content-Type: application/json
Connection: close
Content-Length: 63
->
-> {
-> "data": "2a",
-> "branch_name": "aurora",
-> "water_level": "high level"
-> }
But, if you change to serializeJson(doc, client); you'll send an HTTP like this:
POST /api/ HTTP/1.1
Host: api.xxxxxxx.com
Content-Type: application/json
Connection: close
Content-Length: 63
->
-> {"data":"2a","branch_name":"aurora","water_level":"high level"}
I understood that the problem is to send the data in each line.. for me, changing data for only one line, the problem is gone.
I hope to help!

hapi 18 eventsourcing not working without stream.end()

Try to archive:
I try to use the HTML5 EventSourcing API https://developer.mozilla.org/de/docs/Web/API/EventSource to push events to my client application (javascript).
working example code with plain node http:
With a plain example node implementation it works perfectly and as expected. Example code: https://www.html5rocks.com/en/tutorials/eventsource/basics/
Problem:
When i try to integrate EventSourcing (or SSE) into my API endpoint which is based on hapi (currently using latest - 18.1.0) it does not work.
My route handler code mixed with some code i found:
const Stream = require('stream');
class ResponseStream extends Stream.PassThrough {
setCompressor (compressor) {
this._compressor = compressor;
}
}
const stream = new ResponseStream();
let data = 0;
setInterval(() => {
data++;
stream.write('event: message\n');
stream.write('data:' + data + '\n\n');
console.log('write data...', data);
// stream.end();
}, 1000);
return h
.response(stream)
.type('text/event-stream')
.header('Connection', 'keep-alive')
.header('Cache-Control', 'no-cache')
Findings:
I already searched and it seems since hapi 17.x there they exposed the flush method for the compressor < https://github.com/hapijs/hapi/issues/3658 >, section features.
But it still does not working.
They only way it sends a message is to uncomment the stream.end() line after sending the data. The problem obviously is that i cant send further data if i close the stream :/.
If i kill the server (with stream.end() line commented) the data gets transmitted to the client in a "single transmission". I think the problem is is still somewhere with the gzip buffering even when flushing the stream.
There are some code examples in the hapi github but i got none working with hapi 17 or 18 (all exmaples where hapi =< 16) :/
Someone know how to solve the problem or has a working EventSource example with latest hapi? I would kindly appreciate any help or suggestions.
Edit - Solution
The solution from the post below does work but i had also an nginx reverse proxy in front of my api endpoint it seems the main problem was not my code it was the nginx which had also buffered the eventsource messages.
To avoid this sort of problem add in your hapi: X-Accel-Buffering: no; and it works flawless
Well I just tested with Hapi 18.1.0 and managed to create a working example.
This is my handler code:
handler: async (request, h) => {
class ResponseStream extends Stream.PassThrough {
setCompressor(compressor) {
this._compressor = compressor;
}
}
const stream = new ResponseStream();
let data = 0;
setInterval(() => {
data++;
stream.write('event: message\n');
stream.write('data:' + data + '\n\n');
console.log('write data...', data);
stream._compressor.flush();
}, 1000);
return h.response(stream)
.type('text/event-stream')
}
and this is client code just to test
var evtSource = new EventSource("http://localhost/");
evtSource.onmessage = function(e) {
console.log("Data", + e.data);
};
evtSource.onerror = function(e) {
console.log("EventSource failed.", e);
};
These are the resources that where I found my way to working example
https://github.com/hapijs/hapi/blob/70f777bd2fbe6e2462847f05ee10a7206571e280/test/transmit.js#L1816
https://github.com/hapijs/hapi/issues/3599#issuecomment-485190525

Error -32 EPIPE broken pipe

I am doing a post request with ajax that should return a partialview but I always get following error in log:
Connection id "0HL6PHMI6GKUP" communication error.
Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -32 EPIPE broken pipe
When looking at the debug log, I see that it is loading the partialview data but than I get the error.
I can't find anything on the net about the -32 EPIPE error, could someone help me explain what this error means?
Ajax call
$( "#PostForm" ).submit(function( event ) {
//Ajax call
$.ajax({
type: 'POST',
url: "/url/path/CreateBox",
data: {
"id": $("#RackId").val(),
"Name": $("#Name").val()
},
success: function(result){
$("#modal").html(result);
}
});
});
Controller
[HttpPost]
public async Task<IActionResult> CreateBox(int id, string Name)
{
//Get the info of the given ID
Rack rack = await this._rackAccess.GetByIdAsync(id);
if (rack == null)
{
return NotFound();
}
Box box = new Box();
box.Rack = rack;
if (!string.IsNullOrEmpty(Name))
{
box.Name = Name;
var result = await this._boxAccess.InsertAsync(box);
//Returns a list of boxes
return PartialView("Boxes", await this._boxAccess.ToRackListAsync(rack.ID));
}else{
//Returns form again
return PartialView("CreateBox", box);
}
}
Version
Aspnet core: 1.1.0
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0"
"Microsoft.AspNetCore.Hosting": "1.1.0",
Solution can be found on github were I posted the problem aswell:
https://github.com/aspnet/KestrelHttpServer/issues/1978
Answer of halter73 on github:
The "communication error" usually comes in ECONNRESET, EPIPE, and ECANCELED varieties. Which one you get usually just depends on which platform you're running on, but all three generally mean the same thing: that the client closed the connection ungracefully.
I have a theory why this is happening. I think that the page might be getting reloaded mid-xhr causing the xhr to get aborted. This can be fixed by returning false from your jQuery submit callback.
I took all your dependencies and your jQuery snippet and demonstrated how this page reload can cause an EPIPE on linux and an ECANCELED on Windows in a sample repro at https://github.com/halter73/EPIPE. It uses csproj instead of project.json because I don't have an old CLI that supports project.json easily available.
Maybe due to long time processing on server-side,
communication pipe was broken by overtime mechanism.
Wish this is helpful.

Migrating to self hosted Parse Server isn't giving me the logged user

I'm trying to migrate my Parse server to my own server instance in DigitalOcean. After deploying my parse-server I'm falling in some issue I can't understand.
When you make a call to the Cloud Code, you can retrieve your user as request.user if you have revocable sessions enabled.
Everything is OK, but sometimes (random times) I get this strange behaviour: my request.user doesn't appear in Cloud Code.
I thought it could be a bad session token so I got rid of it by doing:
if (!request.user) {
response.error("INVALID_SESSION_TOKEN");
return;
}
and obbligate the user to log-in again.
This wasn't working, I was getting an INVALID_SESSION_TOKEN everytime I log in, so I decided to debug. These are my steps:
1.- Log in my user, so a _Session object is created:
so the sessionToken is r:a425239d4184cd98b9b693bbdedfbc9c
2.- Make call cloud function (sniff log):
POST /parse-debug/functions/getHomeAudios HTTP/1.1
X-Parse-OS-Version: 6.0.1
X-Parse-App-Build-Version: 17
X-Parse-Client-Key: **** (hidden)
X-Parse-Client-Version: a1.13.0
X-Parse-App-Display-Version: 1.15.17
X-Parse-Installation-Id: d7ea4fa0-b4dc-4eff-9b7d-ff53a1424dcb
User-Agent: Parse Android SDK 1.13.0 (com.pronuntiapp.debug.uat/17) API
Level 23
X-Parse-Session-Token: r:a425239d4184cd98b9b693bbdedfbc9c
X-Parse-Application-Id: **** (hidden)
Content-Type: applicati¡á“WÇX�
Content-Length: 346
Host: 46.101.89.192:1338
Connection: Keep-Alive
Accept-Encoding: gzip
3.- request.user is still not appearing on CloudCode.
EDIT: Reseting the parse-server worked in this case, but not in some others.
Days ago I got the solution.
When you have successfully deployed your Parse server, you will get request.user from any end point of the cloud, but if you call a cloud function from cloud, you won't get this request.user at least you pass the sessionToken:
Parse.Cloud.define("foo", function(request, response) {
if (!request.user) {
response.error("INVALID_SESSION_TOKEN");
return;
}
var countResponses = 0;
var responsesNeeded = 1;
Parse.Cloud.run('bar', request.params, {
sessionToken: request.user.getSessionToken(),
success: function(c) {
countResponses++;
result = c;
if (countResponses >= responsesNeeded) {
response.success(result);
}
},
error: function(error) {
response.error(error);
}
});
});
in this case, foo will have request.user and bar won't, unless you pass sessionToken.

WebSockets : Getting Safari to work with pywebsockets Apache extension

I am trying to get WebSocket running on an Apache server with the help of pywebsocket.
The server is now setup and I am able to make a Websocket connection through Chrome. However, when I try to make a connection through Safari I am getting a "Unexpected response code: 404" and it doesn't appear that the WebSocket connection is able to be established with the server.
Any pointers here would be appreciated. Below is the client side JS code I am invoking to make a connection and the safari header tags vs the Chrome header tags.
function connect() {
if ('WebSocket' in window) {
socket = new WebSocket("ws://localhost/mystream");
} else if ('MozWebSocket' in window) {
socket = new MozWebSocket("ws://localhost/mystream");
} else {
return;
}
socket.onopen = function () {
showResult('Opened');
};
socket.onmessage = function (event) {
showResult(event.data);
};
socket.onerror = function () {
showResult('Error in connection');
};
socket.onclose = function (event) {
var logMessage = 'Closed (';
if ((arguments.length == 1) && ('CloseEvent' in window) && (event instanceof CloseEvent)) {
logMessage += 'wasClean = ' + event.wasClean;
if ('code' in event) {
logMessage += ', code = ' + event.code;
}
if ('reason' in event) {
logMessage += ', reason = ' + event.reason;
}
} else {
logMessage += 'CloseEvent is not available';
}
showResult(logMessage + ')');
};
showResult('Successfully Connected ');
}
Safari Headers :
Origin: http://192.168.1.8
Sec-WebSocket-Key1: 26 ~ 5 75G3 36< 0 U8T
Connection: Upgrade
Host: localhost
Sec-WebSocket-Key2: 1<A 9 4 4l865P5/6L5
Upgrade: WebSocket
Chrome Headers :
Connection:Upgrade
Host:localhost
Origin:http://192.168.1.8
Sec-WebSocket-Key:IAkX9XGWsCZHPQepzYjwxA==
Sec-WebSocket-Version:13
Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00
Managed to get it working now. Safari (5.1) and mobile safari both require the Hixie-75 flag which has experimental support in pywebsockets. The issue was with the entry in the apache conf file, the entry is supposed to be in all lowercase (i.e on) but the sample entry had it in CamelCase (On) . Reverting to all lowercase has solved the issue.
Updated
Those Safari headers are for an older revision of the protocol: Hixie-76. Hixie-76 is a lot less friendly to integration with web servers because there is special data (key3) sent after the headers. I suspect Safari will be updated to the newer version of the protocol (HyBi) in the next release or two.
The HyBi-76 handshake happens in handshake/hybi00.py You might try adding some debug to try and figure out where it is failing. In particular make sure that _get_challenge is actually getting the final 8 bytes (key3) of the challenge that are sent after the headers (this is the part that makes it complicated to handle Hixie-76 in a web server).