WinJS.xhr local network error - windows-8

I am trying to make a simple windows 8 app but I have a problem.
When I try to make a xhr request to a local webserver it fails with the error code: 0x2efd
Sample code:
WinJS.xhr({ url: "http://192.168.0.30" }).then(
function completed(response) {
//var json = JSON.parse(response.responseText);
//var list = new WinJS.Binding.List(json.results);
console.log(response.responseText);
},
function error(error) { console.log(error) },
function progress(progress) { }
);
But when I try a remote IP for instance google.com it works.
What is going wrong?

Did you declare the "private network" capability in your project's application manifest? Double click your application manifest file - It is located under the capabilities tab.

Related

Unable to verify the first certificate Next.js

I am trying to build a new application.
It accesses one API to get some data over HTTPS.
Status2.getInitialProps = async () => {
console.info('ENTERRRRRRRR')
const res = await fetch('https://test.com/api/v1/messages', {
method: 'get',
headers: {
'Authorization': 'Bearer ffhdfksdfsfsflksfgjflkjW50aXNocjEiLCJpYXQiOjE2MDc1ODIzODQsImF1ZCI6InJlY3J1aXRpbmdhcHAtMTAwMC5kZXZlbG9wLnVtYW50aXMuY29tIiwiaXNzIjoicmVjcnVpdGluZ2FwcC0xMDAwLmRldmVsb3AudW1hbnRpcy5jb20ifQ.0jqPutPOM5UC_HNbTxRiKZd7xVc3T5Mn3SjD8NfpEGE',
'Accept': 'application/vnd.api+json'
}
}
)
}
When the browser tries to access this API then it gives me the following error:
Server Error
FetchError: request to https://test.com/api/v1/messages failed, reason: unable to verify the first certificate
This error happened while generating the page. Any console logs will be displayed in the terminal window.
C
To solve this issue I followed this but when tried it, it gave me another error:
'NODE_TLS_REJECT_UNAUTHORIZED' is not recognized as an internal or external command,
operable program or batch file.
The NODE_TLS_REJECT_UNAUTHORIZED solution is a no-go as it is against the main purpose of having a trusted connection between your front-end and API. We run into this error message recently with a NextJS as the front-end, ExpressJS as the back-end, and Nginx as the webserver.
If you or your team are on implementing the API, I would suggest looking into your webserver config and how you are handling the path of the certificates as the problem might be related to a misconfiguration of the intermediate certificate. Combining the certificate + intermediate certificate like so did the trick for us:
# make command
cat {certificate file} {intermediate certificate file} > {new file}
# config file /etc/nginx/conf.d/xxx.conf
ssl_certificate {new file};
create a next.config.js file if you not already have one in your project and add the following to your webpack config:
const webpack = require("webpack");
module.exports = {
webpack: (config) => {
config.node = {
fs: "empty",
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const env = Object.keys(process.env).reduce((acc, curr) => {
acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
return acc;
}, {});
config.plugins.push(new webpack.DefinePlugin(env));
return config;
},
};
Do not use it like this in production. It should only be used in a dev environment.

Error: Timed out while waiting for handshake

I am using scp2 to copy a file to targetPath. config contains host, username, privateKey, path and port.
const client = require('scp2');
export function scpAsync(config, targetPath) {
return new Promise((resolve, reject) => {
client.scp(config, targetPath, err => {
if (!err){
resolve();
} else {
const errorMessage = err;
reject(errorMessage);
}
});
});
}
When doing so I am getting the error:
Error: Timed out while waiting for handshake
I tried to pass also
promptForPass: false
but it did not change anything. Besides that I used debug mode which told me that I am connected to the server and I put a higher setTimeout but then the error is just coming later. I was checking the documentation of scp2 and their GitHub. I use the function like explained there (https://www.npmjs.com/package/scp2) and regarding the error they could fix it with an higher setTimeout (https://github.com/spmjs/node-scp2/issues/107). I tried with a local ftp server, ngrok and ftp on ec2 instance. All with the same problem.
I would be happy to get help. I asked this question also on superuser but did not get an answer:
https://superuser.com/questions/1576964/error-timed-out-while-waiting-for-handshake

How to configure dynamic links for a Firebase project?

Since google is shutting down it's url shortening service, I want to move my project to FDL.
I am using the api to shorten the url following this:
https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_a_long_link
and I am using Postman to call the api but I keep getting this error.
{
"error": {
"code": 400,
"message": "Your project has not configured Dynamic Links. [https://firebase.google.com/docs/dynamic-links/rest#before_you_begin]",
"status": "INVALID_ARGUMENT"
}
}
I am using the correct api key and the project id.
Had the same issue- and thats the answer i got from the firebase team:
Take note that to be able to view your Dynamic Link domain you'll have
to add an app first. If you're using Firebase Dynamic Link as a
substitute to Google Shortener, you can create a sample application
(dummy app) for your project to proceed creating a Firebase Dynamic
Links. Just enter dummy values for the iOS bundle ID or Android
package name (ex: “my.dummy.app”) to continue.
then you'll put the id you'll get from it (e.g. https://dedfgu.app.goo.gl) instead of the place holder (https://abc123.app.goo.gl).
Good luck!
You can try following way
var Url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={API-Key}";
$.ajax({
type: 'POST',
dataType: 'json',
url: Url,
contentType:'application/json',
data: JSON.stringify({
"dynamicLinkInfo": {
"domainUriPrefix": "https://newxpress.page.link",
"link": {Your-Link},
"androidInfo": {
"androidPackageName": "com.newxpress"
},
"iosInfo": {
"iosBundleId": "com.newxpress.iosapp"
}
}
}),
success: function (jsondata) {
console.log(jsondata);
},
error: function (result) {
console.log(result);
}
});

Network error with axios and react native

I have created an API endpoint using the Django python framework that I host externally. I can access my endpoint from a browser (mydomain.com/endpoint/) and verify that there is no error. The same is true when I run my test django server on locally on my development machine (localhost:8000/endpoint/). When I use my localhost as an endpoint, my json data comes through without issue. When I use my production domain, axios gets caught up with a network error, and there is not much context that it gives... from the debug console I get this:
Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:554)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
at XMLHttpRequest.js:493
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:353)
at MessageQueue.js:118
at MessageQueue.__guardSafe (MessageQueue.js:316)
This is my axios call in my react native component:
componentDidMount() {
axios.get('mydomain.com/get/').then(response => { // localhost:8000/get works
this.setState({foo:response.data});
}).catch(error => {
console.log(error);
});
}
If you are trying to call localhost on android simulator created with AVD, replacing localhost with 10.0.2.2 solved the issue for me.
It seems that unencrypted network requests are blocked by default in iOS, i.e. https will work, http will not.
From the docs:
By default, iOS will block any request that's not encrypted using SSL.
If you need to fetch from a cleartext URL (one that begins with http)
you will first need to add an App Transport Security exception.
change from localhost to your ip(192.168.43.49)
add http://
http://192.168.43.49:3000/user/
If you do not find your answer in other posts
In my case, I use Rails for the backend and I tried to make requests to http://localhost:3000 using Axios but every time I got Network Error as a response. Then I found out that I need to make a request to http://10.0.2.2:3000 in the case of the android simulator. For the iOS simulator, it works fine with http://localhost:3000.
Conclusion
use
http://10.0.2.2:3000
instead of
http://localhost:3000
update
might worth trying
adb reverse tcp:3000 tcp:3000
For me, the issue was because my Remote URL was incorrect.
If you have the URL is a .env file, please crosscheck the naming and also ensure
that it's prefixed with REACT_APP_ as react might not be able to find it if named otherwise.
In the .env file Something like REACT_APP_BACKEND_API_URL=https://appurl/api
can be accessed as const { REACT_APP_BACKEND_API_URL } = process.env;
Try
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json"
If you are using android then open your command prompt and type ipconfig. Then get your ip address and replce it with localhost.
In my case, first I used http://localhost:8080/api/admin/1. Then I changed it to http://192.168.1.10:8080/api/admin/1. It worked for me.
Make sure to change localhost to your_ip_address which you can find by typing ipconfig in Command Prompt
Trying adding to your AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I was facing the same issue.
i looked deeper and my
endpoint url was not correct.
By giving axios right exact url, my api worked like charm.
Hope it may help anyone
Above mentioned answers only works if you are using localhost but if your code is hosted on a server and Axios throwing Network Error then you can solve this by adding one line.
const config = {
method: 'post',
url: `${BASE_URL}/login`,
headers: {
'Content-Type': 'multipart/form-data'. <----- Add this line in your axios header
},
data : formData
};
axios(config).then((res)=> console.log(res))
I'm using apisauce dependancy & Adding header work for me with React Native Android.
Attach header with request like below:
import { create } from 'apisauce';
const api = create({
baseURL: {baseUrl},
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
export async function empLogin(data) {
try {
const response = api.post('Login', data);
return await response;
} catch (error) {
console.log(error);
return [];
}
}
before:
axios.get("http://localhost:3456/apt")
.then(
response => {
alert(JSON.stringify(response));
....
}
)
.catch(function(error) {
alert(error.message);
console.warn(error.response._response);
});
I get Error "Network error" Failed to connect to the localhost after that, I make some steps to resolved the error.
Network Error related to axios resloved by the disabling the system firewall and access from the system IP Address like
axios.get("http://192.168.12.10:3456/apt")
.then(
response => {
alert(JSON.stringify(response));
....
}
)
.catch(function(error) {
alert(error.message);
console.warn(error.response._response);
});
For me adding "Accept" in headers resolved the problem:
Accept: 'application/json'

Unable to connect to adapter

I have following code called when loading the page:
var resourceRequest = new WLResourceRequest(
"adapters/adapter-name/rest/init/" + timeStamp,
WLResourceRequest.GET
);
However it returns error in my console:
GET http://localhost:10080/project-name/adapters/adapter-name/rest/init/0 404
(Not Found)
While this code works:
function wlEnvInit() {
console.log("CONNECTING 1111");
WL.Client.connect({c
onSuccess: function(){
console.log("CONNECTED 2222");
},
onFailure: function(error) {
console.log("ERROR IN CONNECTION");
console.log(error);
}
});
}
How to troubleshoot this?
Make sure the adapter is really deployed by visiting the console
Make sure that your application is pointing to an IP address of the host machine where the MobileFirst Server is deployed to
Make sure your adapter call is correct
Example calling:
Client side:https://github.com/MobileFirst-Platform-Developer-Center/ResourceRequestCordova/blob/release80/www/js/index.js#L54
Server side: https://github.com/MobileFirst-Platform-Developer-Center/Adapters/blob/release80/JavaAdapter/src/main/java/com/sample/adapter/JavaAdapterResource.java#L25