Flutter Error: Unsupported operation: Platform._version on web - ajax

I use packages
http: ^ 0.12.2
this is my iport
import 'package: http / http.dart' as http;
import 'dart: io';
import 'dart: convert';
for retrieving the data from a server. It works fine with Android and iOS. But on the web I get the error message Unsupported operation: Platform._version
this is my function:
Future getUserData() async {
var url_ = "${APIDomain}/antragsteller/1";
HttpClient client = new HttpClient();
client.badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
HttpClientRequest request = await client.getUrl(Uri.parse(url_));
request.headers.set('content-type', 'application/json');
request.headers.set('Access-Control-Allow-Origin', '*');
HttpClientResponse response = await request.close();
String reply = await response.transform(utf8.decoder).join();
this.userData = jsonDecode(reply);
}
the return value is then of course empty. My internet search did not produce any useful results.
Can someone please help me find the cause and solve the problem. Thank you!

This was caused by an issue on Dart SDK libraries and Flutter for web as documented on this GitHub issue thread. This has been resolved for the http plugin, updating to the latest version of the plugin should solve the issue.

Related

How to enable trust proxy in express. Nestjs app

I am learning nestjs and, building an app but my ip is behind the proxy,
Nestjs documentation says enable the trust proxy in express,
https://docs.nestjs.com/security/rate-limiting
I am getting trouble how to do that and then how to find the IP.
Try this
import { NestExpressApplication } from "#nestjs/platform-express"
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.set('trust proxy', 1);
Credit:
Nestjs Docs Offical
Nestjs Docs But Not Offical
Express behind proxies
for Fastify adapter trustProxy accept true, number, array of CIDRs, and string of comma separated CIDRs and should be passed like that:
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({
// #see https://www.fastify.io/docs/latest/Reference/Server/#trustproxy
trustProxy: process.env.TRUST_PROXY?.match(/\d/)
? +process.env.TRUST_PROXY
: process.env.TRUST_PROXY,
}),
);
await app.listen(port, process.env.ADDRESS); // ADDRES = "undefined" or "0.0.0.0"

getting weather info using flutter http package

i want to get current weather information of coordinated base from openweathermap API.
For this purpose i am using flutter's HTTP Package.
the problem is here when i use this method
One more problem is that... I got these coordinates on Memu App Player but does not gives on Real android device and Android Studio's Own Emulator.
void getWeatherData()async{
String url = 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=331533c0cc2197e929ea79cdb2a70e33';
Response response = await get(Uri.parse(url));
print(response.body); }
this should give me API result completely but it gives me this error when i run my app.
Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform: http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=331533c0cc2197e929ea79cdb2a70e33
This is how I did it. I'm going through a course in Udemy that is going over what you are asking.
void getData() async {
var url = Uri.https('samples.openweathermap.org', 'data/2.5/weather', {
'lat': '35',
'lon': '139',
'appid': 'b6907d289e10d714a6e88b30761fae22'
});
http.Response response = await http.get(url);
print(weatherResponse.body);
}
Remember to use
import 'package:http/http.dart' as http;

Making credentialed requests with Bokeh AjaxDataSource

I have a plot set up to use an AjaxDataSource. This is working pretty well in my local development, and was working as deployed in my Kubernetes cluster. However, after I added HTTPS and Google IAP (Identity-Aware Proxy) to my plotting app, all of the requests to the data-url for my AjaxDataSource are rejected by the Google IAP service.
I have run into this issue in the past with other AJAX requests to Google IAP-protected services, and resolved it by setting {withCredentials: true} in my axios requests. However, I do not have this option while working with Bokeh's AjaxDataSource. How do I get BokehJS to pass the cookies to my service in the AjaxDataSource?
AjaxDataSource can pass headers:
ajax_source.headers = { 'x-my-custom-header': 'some value' }
There's not any way to set cookies (that would be set on the viewer's browser... which does not seem relevant in this context). Doing that would require building a custom extension.
Thanks to bigreddot for pointing me in the right direction. I was able to build a custom extension that did what I needed. Here's the source code for that extension:
from bokeh.models import AjaxDataSource
from bokeh.util.compiler import TypeScript
TS_CODE = """
import {AjaxDataSource} from "models/sources";
export class CredentialedAjaxDataSource extends AjaxDataSource {
prepare_request(): XMLHttpRequest {
const xhr = new XMLHttpRequest();
xhr.open(this.method, this.data_url, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-Type", this.content_type);
const http_headers = this.http_headers;
for (const name in http_headers) {
const value = http_headers[name];
xhr.setRequestHeader(name, value)
}
return xhr;
}
}
"""
class CredentialedAjaxDataSource(AjaxDataSource):
__implementation__ = TypeScript(TS_CODE)
Bokeh extensions documentation: https://docs.bokeh.org/en/latest/docs/user_guide/extensions.html

Whoops! Lost connection to http://198.x.x.x:hostnumber/websocket

I am using SocksJs and getting every time Whoops! Lost connection to Http or if I changed the link to ws://198.x.x.x:hostnumber/websocket then i will get
'SyntaxError: The URL's scheme must be either 'http:' or 'https:'. 'ws:' is not allowed.
SyntaxError: The URL's scheme must be either 'http:' or 'https:'. 'ws:' is not allowed.'
also, I am sharing my code
import * as Stomp from 'stompjs';
import * as SockJS from 'sockjs-client';
connectNew() {
const socket = new SockJS(this.serverUrl);
this.stompClient = Stomp.over(socket);
this.stompClient.connect('', '', () => {
console.log('success');
});
}
Please help if anybody knows the answer I want to run this code on my mobile phone

Request to Parse API using RestSharp.Portable in Xamarin

I'm having problems trying to do a GET request to Parse REST API using RestSharp.Portable in a PCL Xamarin project.
The problem occurs in the line:
var result = await client.Execute (request);
Throwing an exception and stopping the app (Android).
This is the function i'm using.
public async Task<EventItem> GetAListOfAllEvents ()
{
using (var client = new RestClient (new Uri ("http://api.parse.com"))) {
var request = new RestRequest ("1/classes/Event/2yHLWDUlv3");
request.Method = HttpMethod.Get;
request.AddHeader ("Content-Type", "application/json");
request.AddHeader ("X-Parse-Application-Id", "myAppId");
request.AddHeader ("X-Parse-REST-API-Key", "myAPIparseKey");
var result = await client.Execute (request);
return result;
}
}
I hope someone could help me, thanks.
Remove this line.
request.AddHeader ("Content-Type", "application/json");
Request is failing because of it (probably as you have no actual content in your GET request).

Resources