I have geth running in remote server and is protected using HTTP Basic Auth.
I tried the below two methods. both don't work:
let web3 = new Web3(
new Web3.providers.HttpProvider(
'http://' + "username" + ':' + "password" + '#'+ "52.43.83.54/iimigdmb" + ':' + "31988"
)
)
As per official docs:
web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://' + "52.43.83.54/iimigdmb" + ':' + "31988", 5000, "sad", "asd"));
Is there any other way to achieve this:
Related
I am using vb 2008 .net 3.5.
I am trying to use sms api.
I have error on httpclient cannot find and I cannot find it on reference.
sms provider code :
HttpClient client = new HttpClient();
Uri baseAddress = new Uri("https://smsmisr.com/");
client.BaseAddress = baseAddress;
var sendtime = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");
HttpResponseMessage response = client.PostAsJsonAsync(
"api/webapi/?" +
"username=XXXxx" +
"&password=XXXXXX" +
"&language= 3 Or 2 Or 1" +
"&sender=Your Sender " +
"&mobile=2012XXXXXX, 2011XXXX" +
"&message=Encoded Message" +
"&DelayUntil="+sendtime
).Result;
I am accessing API using Google Apps Script. I am looking for a https://developer.xero.com/documentation/api/reports#TrialBalance
I have tried with the API code as but I get signature invaid as reposnse result [19-09-03 19:45:46:402 IST] oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20signature
function doGet(e) {
getTrialBalances();
}
function getTrialBalances() {
var oauth_nonce = createGuid();
var oauth_timestamp = (new Date().valueOf() / 1000).toFixed(0);
var CONSUMER_KEY = 'B7D5YA8D1HWHUZIGXL1AZS44N'
var PEM_KEY = '-----BEGIN RSA PRIVATE KEY-----' +
'ANIICXAIBAAKBgQC2WiSrkljVAZIgNUe/nBZ+PGJzauBJ6szlzPow1XoySkVikswui1IX4wUzgLmvnCmnQkRPgA43oiZqmK1H68MvirYzQkMa3sETViQAOiRPOrDEUTkemKiDXpaIKedD8T6/P9qzgtgU5hlP/R45POanIuNFvYPdpkm2yybOmI+1TwIjAQABAoGADt/3kc9UU7vXEa2G9shixVVjqoqTVTREFpLL7ePcHfIVCt9yrHFM9wnbyMG9uRZRIyDmbpumClROJImuADxc6reamXdTMX0OwEPogAREnY2diadjVjicoMYYEcdbb6pgDSOWcYtamNmzD5tkPI0bPFU+fTdpzGCOCECQQDvZTha0SRcCZPZipCs7PtAOWtMP1FBe140+cvsWiq2eHMmYDtIi7Mx210i3wzz4+Izl4jXeICKprppaBlJxSFZAkEAwwALfSnpqWeop86nnUICOPmksbK2rTtNVd+WGiAK4reUDJArOOXdDm7fYqppQNA35hxcRmvxeKK7jSYLQYHO5wJAeLFubRL+IszNVqLud9Buh52rQ+C0RbA9+bVqozl+SUqGu3VOzi9oY5114kvUCu38MAiY/BELtVuDpfrOrQuO2QJAHrZZGOOLC8VpyNRBjgEhfHvFNr+hCfO3IHlQmNjHHiIvzTK/u/xoLqfDwzR30194DmQVHHpP0+I9i+OcDjs1rQJBAJMY6h4QdYSFpTPxUOPA/s1lKVvJUIzgzX6oMfvc4TDb0RCz4nCvjJ1NEqPjveB6ze5TzC8BzfRW/aUh49vmgRA=' +
'-----END RSA PRIVATE KEY-----';
var payload = '';
var URL = 'https://api.xero.com/api.xro/2.0/Reports/TrialBalance';
var signatureBase = "GET" + "&" +
encodeURIComponent(URL) + "&" +
encodeURIComponent('date=2019-02-01') + "&" +
encodeURIComponent("oauth_consumer_key=" + CONSUMER_KEY +
"&oauth_nonce=" + oauth_nonce + "&oauth_signature_method=RSA-SHA1&oauth_timestamp=" +
oauth_timestamp + "&oauth_token=" + CONSUMER_KEY + "&oauth_version=1.0");
var rsa = new RSAKey();
rsa.readPrivateKeyFromPEMString(PEM_KEY);
var hashAlg = "sha1";
var hSig = rsa.signString(signatureBase, hashAlg);
var oauth_signature = encodeURIComponent(hextob64(hSig));
var authHeader = "OAuth oauth_token=\"" + CONSUMER_KEY + "\",oauth_nonce=\"" + oauth_nonce +
"\",oauth_consumer_key=\"" + CONSUMER_KEY + "\",oauth_signature_method=\"RSA-SHA1\",oauth_timestamp=\"" +
oauth_timestamp + "\",oauth_version=\"1.0\",oauth_signature=\"" + oauth_signature + "\"";
var headers = {
"Authorization": authHeader,
"Accept": "application/json"
};
var options = {
"headers": headers,
'method': 'GET',
'payload': payload,
'muteHttpExceptions': true,
};
var requestURL = URL + '?date=2019-02-01';
var response = UrlFetchApp.fetch(requestURL, options);
var responseXml = response.getContentText();
Logger.log(responseXml);
}
function createGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16)
});
}
For RSA signing I have used https://github.com/csi-lk/google-app-script-xero-api/blob/master/jsrsasign.gs
UPDATE 2:
I code this, but still not able to get the result
var signatureBase = encodeURIComponent("GET" + "&" + URL + "&" + 'date=2019-02-01' + "&" + "oauth_consumer_key=" + CONSUMER_KEY +
"&oauth_nonce=" + oauth_nonce + "&oauth_signature_method=RSA-SHA1&oauth_timestamp=" +
oauth_timestamp + "&oauth_token=" + CONSUMER_KEY + "&oauth_version=1.0");
Before reading the rest of my answer can you please urgently reset your applications Consumer Key/Secret, as well as create and upload a new public certificate to the developer portal as you've provided both in your question.
At least one issue you're running into that I can spot is how you're building up the signature base string.
Only the initial & should be left unencoded, however the rest of them in the signature base string should be encoded. It looks like the & after the encoded URL and encoded date query param are being left unencoded.
Edit:
The following two lines are leaving the &s out ouf encoding, but they need to be included in the uri encoding
encodeURIComponent(URL) + "&" +
encodeURIComponent('date=2019-02-01') + "&" +
I am using geonames.org to auto populate my address fields based on zip code. I have been using there api and it was woking recently when I saw the following error:
net::ERR_NAME_NOT_RESOLVED
This is the bit of code i'm using to make the api call:
$.getJSON("https://www.api.geonames.org/postalCodeLookupJSON?postalcode=" + zip[0] + "&country=" + country + "&username=myUsername", function(response) {
//code for my view
$(".locked").attr("readonly", false);
var places = response.postalcodes;
if (places.length > 1){
$.each(places, function(i, place) {
$('#rightSideZip').append('<li class="zipLookups" data-city="' + place.placeName + '" data-zip="' + place.postalcode + '" data-state="' + place.adminCode1 + '"><span>' + place.postalcode + ' – ' + place.placeName + '</span><p>' + place.adminName1 + '</p></li>')});
} else {
city.val(response.postalcodes[0].placeName).blur();
state.val(response.postalcodes[0].adminCode1).blur();
lat.val(response.postalcodes[0].lat).blur();;
lng.val(response.postalcodes[0].lng).blur();;
latitude = response.postalcodes[0].lat;
longitude = response.postalcodes[0].lng;
}
});
});
Can I just not use this api anymore until they get the certificate or is there a way around it?
I am new to Node server. In my program I fetched some data from data base as
connection.query("SELECT * from login where username='" + uname + "' and password='" + pwd + "' ", [uname, pwd], function (err, rows)
{
var employees = (JSON.stringify(rows));
console.log("Inside server "+employees )
});
Now in console i got some thing like
[{"user_id":7,"username":"vb","password":"vbv"}]
Now my Question is how i could get the value username from employees. I have tried few things like
employees[0]["username"] OR employees.username etc..
Because you stringify it, it becomes string so you can't access like that. Just use it as is.
JSON.stringify(rows) only allow you to pretty print the data.
To access it you were right with employees[0]["username"]
connection.query("SELECT * from login where username='" + uname + "' and password='" + pwd + "' ", [uname, pwd], function (err, employees)
{
console.log("Inside server " + JSON.stringify(employees));
console.log('Employee 1: ' + employees[0]["username"]);
});
I'm trying to write data to a firebase database using Google Apps Script HTTP PUT Request. Here is what I have for code. I've debugged every line and everything works except for the actual PUT request.
Web page with one button in it.
<section>
<input onclick="WriteInput()" type="button" value="Save Input">
</section>
<script>
function onSuccess() {
alert("on success ran");
};
function onFailure() {
alert("on failure ran");
};
function WriteInput() {
alert("it ran");
google.script.run.withFailureHandler(onFailure)
.withSuccessHandler(onSuccess)
.putToFire();
}
</script>
This is the server side .gs code:
function doGet(){
return HtmlService.createTemplateFromFile('WriteToFirebase')
.evaluate() // evaluate MUST come before setting the NATIVE mode
.setTitle('Test Write')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
function putToFire() {
var payload =
{
"first" : "Jack",
"last" : "Sparrow"
};
var options =
{
"method" : "put",
"payload" : payload
};
UrlFetchApp.fetch("https://SampleChat.firebaseIO-demo.com/users/fred/name.json", options );
Logger.log(options);
}
This is the Google documentation for issuing a HTTP request with Apps Script:
fetch url Google Documentation
This is the Firebase REST API documentation:
Firebase REST API
in cURL -X is to set the type of request. E.g. PUT, POST, etc and -d is the indicate that data is to follow: The match up with Google Fetch is to set the params.
I must be just missing a syntax setting or something.
I actually found an answer to my problem. I can't remember what the error message was. I changed
THIS:
var options =
{
"method" : "put",
"payload" : payload
};
TO THIS:
var options = {"method" : "put", "payload" : payload};
And it started working. I'm guessing that the multi-line code had end of line return characters in it, that Firebase would not parse. That's just my guess.
This example shows payload, options and the Apps Script UrlFetchApp.fetch service.
var payload = "{\"aa\" : \"" + UserID + "\", \"ab\" : \"" + Maker + "\", \"ac\" : " +
AskingPrice + ", \"ad\" : \"" + Type +
"\", \"ae\" : \"" + Description + "\", \"af\" : \"" + Function + "\", \"ag\" : \"" +
Cosmetic + "\", \"ah\" : \"" + dbID +
"\", \"ai\" : \"" + IPaddr + "\"}";
var options = {"method" : "put", "payload" : payload};
UrlFetchApp.fetch("https://MyFireBaseDatabaseName.com/" + Ctgry + "/"
+ dbID + "/.json", options );