Flutter HTTP Get Request Wrong Port - dart

i try to perform a GET request to my localhost server. i run the flutter application on a external device with android studio and the XAMPP/php server with the endpoint run on the pc too. now is the problem every time i run the GET request it run on a wrong port. i write in the url port 80 but flutter perform it on 53555 or other 53...
i try to change the url but nothing changed.
here is the code and the error message
var url = new Uri.http("192.168.2.23:80", "/login", {"username":username,"password":password});
print(url);
var client = http.Client();
http.Response response = await client.get(url);
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
this is the error
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.2.23, port = 53695

Related

I am not able to call rest api which is in another container running at localhost:9090, using localstack 12.5 lambda (running at 4566 port)

localstack 12.5
dummy.py file for lambda hanlder
import sys
import requests
def handler(event, context):
print("Inside handler")
x = requests.get('http://localhost:9090/ping')
print(x.status_code)
return str(x.content)
In handler when i am calling get api which is in another container i am getting connection refused error.
Error:
"ConnectionError","errorMessage":"HTTPConnectionPool(host='localhost', port=9090): Max retries exceeded with url:
Caused by NewConnectionError('\u003curllib3.connection.HTTPConnection object at 0x7ff8185c8ad0\u003e: Failed to establish a new connection:
However with postman I am able to hit http://localhost:9090/ping API
Also If I replace x = requests.get('https://w3schools.com') then I am getting 200 .
The issue has been resolved by adding below env variable in localstack
LAMBDA_DOCKER_NETWORK="host"

Requesting webSocketDebuggerUrl from Chrome-Headless in Docker Container

Setup
Trying to run chrome headless as a container (Image: https://hub.docker.com/r/alpeware/chrome-headless-trunk) in my docker-compose and connecting to it from another container.
Problem
To actually connect to chrome inside the container, I first need to retrieve the webSocketDebuggerUrl, which is available at http://0.0.0.0:9222/json/version of the chrome-headless.
The Problem is: my request to this path always fails with
RequestError: Error: connect ECONNREFUSED 0.0.0.0:9222
and cant get the webSocketDebuggerUrl to connect to chrome.
Some more Info
Also if I visit http://0.0.0.0:9222/json/version in my browser myself, copy the url and hardcode it into my puppeteer.connect(), it ONLY works as expected, if I replace the address of '0.0.0.0' to my (linked) container-name (specified in docker-compose): http://chrome:9222/json/version
If I try to request the webSocketDebuggerUrl from /json/version while using container-name address (http://chrome:9222/json/version) i get the error
StatusCodeError: 500 - "Host header is specified and is not an IP address or localhost."
My Code (abstraction)
const rp = require('request-promise')
const puppeteer = require('puppeteer-core')
let url = await rp({uri:'http://0.0.0.0:9222/json/version', json: true }).then(res => res.webSocketDebuggerUrl)
let browser = await puppeteer.connect({ browserWSEndpoint: url })
Well, since the errorMessage from the 500 said "host is specified", ist just set that header to empty, and now I can successfully request the webSocketDebuggerUrl.
The solution feels a bit hacky, so if anyone has a suggestion on how to improve it I'd be happy:
const puppeteer = require('puppeteer-core')
const rp = require('request-promise')
let websocket = await rp({uri:'http://chrome:9222/json/version', json: true, headers: {'Host': ''} })
.then(res => res.webSocketDebuggerUrl.replace('ws://','ws://chrome:9222'))
let browser = await puppeteer.connect({ browserWSEndpoint: websocket })

Unexpected HTTP Request: POST /mqtt/auth

I am new to emqtt. I am trying to use emq_auth_http but it is not working.
I have these 3 requests to console some data and send data back with status 200.
app.post('/mqtt/auth', function(req, res) {
console.log('This is body ', req.body);
res.status(200).send(req.body);
});
app.post('/mqtt/superuser', function(req, res) {
console.log('This is body in superuser ', req.body);
res.status(200).send(req.body);
});
app.get('/mqtt/acl', function(req, res) {
console.log('This is params in acl ', req.params);
res.status(200).send(req.body);
});
Requests are working fine on postman.
I have configured my emqtt on windows with docker. I have placed my config file in /etc/plugins/emq_auth_http.conf.
This is my config file
## Variables: %u = username, %c = clientid, %a = ipaddress, %P = password, %t = topic
auth.http.auth_req = http://127.0.0.1:3000/mqtt/auth
auth.http.auth_req.method = post
auth.http.auth_req.params = clientid=%c,username=%u,password=%P
auth.http.super_req = http://127.0.0.1:3000/mqtt/superuser
auth.http.super_req.method = post
auth.http.super_req.params = clientid=%c,username=%u
## 'access' parameter: sub = 1, pub = 2
auth.http.acl_req = http://127.0.0.1:3000/mqtt/acl
auth.http.acl_req.method = get
auth.http.acl_req.params =
access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t
Then I enabled emq_auth_http from dashboard
Now when I tried to connect my mqtt client to my server it is not calling the api. It logs
09:28:29.642 [error] Unexpected HTTP Request: POST /mqtt/auth
09:28:29.644 [error] Client(19645050-9d1b-4c50-acf9-
c1fe7e69eea8#172.17.0.1:60968): Username 'username' login failed for 404
Is there anything I missed? Why it is not working?
Thanks
127.0.0.1 in a container refers to the container itself and not the host machine. you should set the host machine ip,you can obtain the host machine ip from a container by issuing the command /sbin/ip route|awk '/default/ { print $3 }' which could be found here
ps: this way you can get the ip of docker machine and not the host ,if your service is served by windows you can reach the ip of host machine from the container which is 10.0.75.1. you can find it in
How to connect to docker host from container on Windows 10 (Docker for Windows)

unhandled socket.io url when connecting with ios socket.io client

I have a problem connecting with my socket.io server hosted on cloud9 for testing purposes. Here is how my server looks like:
var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io').listen(http);
io.on('connection', function(socket){
console.log('a client has been conected');
socket.on('update', function(){
console.log('receved an update :)');
})
});
http.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function(){
var addr = http.address();
console.log("Chat server listening at", addr.address + ":" + addr.port);
});
and here is my iOS client:
func initalSocketManager(){
self.socket = SocketIOClient(socketURL: "https://applewatchnode-seven-ply.c9users.io")
self.socket.connect()
self.socket.on("connection") {data, ack in
print("socket connected")
}
}
For any reason I'm not able to connect to my socket server. When I run my iOS app the server logs the following info:
info - unhandled socket.io url
Any help will be highly appreciated.
Your server code is a non-ssl HTTP listener on port 3000. Your iOS client code is trying to connect over SSL (port 443). They will never find each other.
Change your iOS code to
http://applewatchnode-seven-ply.c9users.io:3000/

Appium Server not connected and throwing org.openqa.selenium.remote.UnreachableBrowserException

I have recently started mobile devices automation on appium with the java language.
I am trying to run the initial setup code through program it is returning this failure message.
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
When Manual run Appium server it doesn't have any errors and server started; the android apk file is installed.
Below is my code; Eclipse doesn't show any errors. I use Android Emulator for this Initial test. Appium and Java Project code in same host machine.
public void setup() throws MalformedURLException {
WebDriver AppWebDriver = null;
AppiumDriver ApUMDriver = null;
AndroidDriver AppiumURLDriver;
URL Serverurl;
// TODO Auto-generated method stub
DesiredCapabilities Appiumcapabiliy = new DesiredCapabilities();
File appDir = new File("c:\ApkbuildsDir");
File app = new File(appDir, "xxx.apk");
Appiumcapabiliy.setCapability("devicename","Device11");
Appiumcapabiliy.setCapability("platformname","Android");
Appiumcapabiliy.setCapability("platformVersion","4.2.2");
Appiumcapabiliy.setCapability("app-package","packagename");
Appiumcapabiliy.setCapability("app-activity","activityscreen");
Appiumcapabiliy.setCapability("app", app.getAbsolutePath());
Serverurl = new URL("http://127.0.0.1:4723/wd/hub");
AppWebDriver = new AndroidDriver(Serverurl,Appiumcapabiliy);
AppWebDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
ApUMDriver.findElement(By.name("My Card"));
}
Could you please guide me how to eliminate this server connect error through program.
Regards, Kiran
Looks like "Appium server" instance is NOT running in your machine. That is, http://127.0.0.1:4723/wd/hub
Please start the Appium server on 4723 port and try execute your code.

Resources