Hhi, i try to unlock my android keys with the phonegap WRITE API and more precisely with this method: https://build.phonegap.com/api/v1/keys/android/257852?auth_token=mytoken
This method returns :
{
"id":257852,
"title":"****",
"platform":"android",
"created_at":"2017-07-06 01:42:56 -0700",
"last_used":"2017-07-11 06:00:33 -0700",
"link":"/api/v1/keys/android/257852",
"default":false,
"alias":"****",
"locked":true
}
The problem is that suddenly my key is not unlock as you can see in the return and also on the web interface of build.
I do this request with javascript and jquery ajax :
$.ajax({
url: "https://build.phonegap.com/api/v1/keys/android/257852",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
type: 'PUT',
dataType: 'json',
contentType: 'application/json',
processData: false,
data: '{"key_pw":"pass","keystore_pw":"pass"}',
success: function (data) {
alert(JSON.stringify(data));
},
error: function(){
alert("Cannot get data");
}
});
I do not understand what i do wrong...
Thank you for your help and sorry for my bad english !
EDIT :
Ok my bad.. i just give this to data field :
data: '{"key_pw":"pass","keystore_pw":"pass"}',
and API need something like that :
data: 'data={"key_pw":"pass","keystore_pw":"pass"}',
Related
I am making a project for local use using jQuery and Node.js + Express API.
When I "place an order" using Postman there is no problem:
When I do, what seems to me, the same with jQuery, I get an internal server error 500:
$.ajax({
type: "post",
url: "http://localhost:3001/roomorder",
data: {
roomOrderLines: global_orderSummary,
},
dataType: "json",
success: (placeOrderResult) => {
$('#appContent').html(`success!`);
},
error: (xhr, ajaxOptions, thrownError) => {
global_setError("An error occurred. / "+xhr.status+" / "+thrownError);
}
});
the global_orderSummary looks like this when I console.log it, looks identical to me as what I use as data in Postman:
Any help would be much appreciated!
I had to make these adjustments, now it works:
type: "post",
url: "http://localhost:3001/roomorder",
data: JSON.stringify ({roomOrderLines: global_orderSummary}),
dataType: "json",
contentType: "application/json",
I am trying to get access_token utilizing jQuery. Problem is, that I cannot get that token (server is running on localhost). Server works fine (I tried that with postman), but I cannot get it with jQuery.
Browser writes after clicking on the button.
The resource from “http://localhost:8080/oauth/token?callback=jQuery34105901959820360243_1562175129954&grant_type=password&client_id=my-client&client_secret=my-secret&username=test%40seznam.cz&password=Peter&_=1562175129955” was blocked due to MIME type (“application/json”) mismatch (X-Content-Type-Options: nosniff).
jQuery function to get access_token
function authenticateUser(email, password) {
var body = {
grant_type: 'password',
client_id: 'my-client',
client_secret: 'my-secret',
username: "test#seznam.cz",
password: "Peter"
};
$.ajax({
url: 'http://localhost:8080/oauth/token',
crossDomain: true,
type: 'POST',
dataType: 'jsonp',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
header: {"Access-Control-Allow-Origin": "*"},
data: body,
complete: function(result) {
alert(result);
},
success: function(result) {
alert(result + " OK!");
},
error: function(result) {
alert(result + " CHYBA");
},
});
return true;
}
If the javascript file is served by the same server that gives out the tokens then there's no need to use the full url in your jquery ajax code (and there's no need to indicate crossDomain=true). It also seems that your server is expecting json content type instead of url-encoded
use
url: '/oauth/token',
crossDomain: false,
...
contentType: 'application/json; charset=UTF-8',
To make the request
Edit
Trye this way:
$.post("/oauth/token",body,
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
Hope this helps
I have a javascript code that calls a web service from another server, it's working, but i need to call it from code behind due to an http call request issue, following my code :
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://10.8.111.12:7181/CatchEventLink.asmx/CollectDataLink",
data: JSON.stringify({ "pDataDictionnary": lDataCollected }),
dataType: "json",
async: true,
success: function (data, textStatus) {
if (textStatus == "success") {
//alert('success');
}
},
error: function (exception) {
//alert('Exeption : ' + exception);
}
});
Any suggestions please??
Trying the basic stuff,
request with data and response with data and print it with jQuery and Rails
This is the front code.
$("#internal_btn").click(function() {
//window.alert("clicked internal btn!");
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/room/test",
//data: "{'data1':'" + value1+ "', 'data2':'" + value2+ "', 'data3':'" + value3+ "'}",
data: {name:"ravi",age:"31"},
dataType: "json",
success: function (result) {
//do somthing here
window.alert("success!!");
},
error: function (){
window.alert("something wrong!");
}
});
});
in here, if the user clicks internal_btn this event happens and goes to the servide
room/test action.
ok this is fine. But I'm not sure how to send the data.
If i run this, i have an error like this.
MultiJson::LoadError
795: unexpected token at 'name=ravi&age=31'
Can i know what the problem is?
Also, is there are good example with this request and response with json format?
I googled a lot, but not satisfied with the result :(
Try to use stringify your data or use GET method like,
data : JSON.stringify({name:"ravi",age:"31"}),
Full Code,
$.ajax({
type: "POST",// GET in place of POST
contentType: "application/json; charset=utf-8",
url: "/room/test",
data : JSON.stringify({name:"ravi",age:"31"}),
dataType: "json",
success: function (result) {
//do somthing here
window.alert("success!!");
},
error: function (){
window.alert("something wrong!");
}
});
I have a code which tries to post to a api. But I keep getting 401 in firefox and 400 in safari
$.ajax({
type: "POST",
url: "http://url.com",
dataType: "json",
async: "false",
data: form_data,
beforeSend: function(xhr1) {
xhr1.setRequestHeader("Authorization", "Basic " + encodeBase64(username + ":" + password))
},
success: function (data,status,xhr){
//do something
}
});
I followed instructions from here
http://dothow.blogspot.com/2009/05/http-basic-authentication-with-jquery.html?showComment=1270999665472#c3021624182011440325
*encodeBase64 is part of a library function