In the following postman pre request script, I need to call multiple requests before I make an actual postman request.
Firstly, it will call session API to retrieve the session id
After session id is success only, then I need to call customer signon to make the user logged in.
So I did the following changes in my postman prerequest script but some how the LocalSessionId in the customer signon request is undefined.
const sessionRequestData = {
url: "http://myurl.com/session",
method: 'POST',
header: { 'content-type': 'application/json' },
body: {
mode: 'raw',
raw: JSON.stringify({
"device": {
"id": "web",
"type": "WEB"
}
}
};
pm.sendRequest(sessionRequestData, function (err, res) {
var jsonData = res.json();
if (err) {
console.log("mailman: error retrieving session id"+err);
}
else {
console.log("mailman: retrieved session data succesfully"+ jsonData.session.id);
pm.variables.set("LocalSessionId", jsonData.security.session.id);
}
});
const customerSignonRequestData = {
url: "http://myurl.com/CustomerSignOn",
method: 'POST',
header: { 'content-type': 'application/json' },
body: {
mode: 'raw',
raw: JSON.stringify( "customerRequest": {
"identities": {
"identity": [
{
"data": "sessionId",
"value": `${pm.variables.get("LocalSessionId")}`
}
]
}
});
pm.sendRequest(customerSignonRequestData, function(err, res){
console.log("customer sign on request "+ JSON.stringify(customerSignonRequestData.body.raw))
var jsonData = res.json();
if (err) {
console.log("mailman: unable to signon"+err);
} else {
console.log("mailman: login successful"+ JSON.stringify(jsonData))
}
});
Can anyone suggest how can I make sure that the customer signon is called after the session is retrieved only.
Related
I have a problem typing a data request to api. I use laravel vue and axios to make a request. the following problem appears
exception: "Symfony\Component\HttpKernel\Exception\HttpException"
file: "/var/www/html/accurate/ibn_accurate_web_api/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php"
line: 383
message: "CSRF token mismatch."
<script>
import axios from "axios"
// import pagination from 'laravel-vue-pagination'
export default {
name: "branch-list",
components: {
// pagination
},
data() {
return {
branch: {
type: Object,
default: null
}
}
},
mounted() {
this.list()
},
methods: {
async list(page = 1) {
await axios.post("http://ibn.tes/api/accurate/branch", {
code_database: 550724,
headers:{
"X-CSRF-TOKEN": window.Laravel.csrfToken
}
}).then(({ data }) => {
this.branch = data
console.log(data);
}).catch(({ response }) => {
console.error(response)
})
}
}
}
</script>
I'm sending a get request from an angularjs 1.5x client to a Java HTTP method and in the client I will print the response which will contain some JSON data.
// method from an angular service that sends ajax requests
this.getTask = function(taskName) {
var url = 'http://localhost:9998/tasks/' + taskName;
var config = {
headers: {
'Content-Type': 'application/json'
}
};
$http.get(url, config)
.then(function successCallback(response) {
console.log(response.data);
}, function errorCallback(response) {
console.log(response);
});
};
The request executes successfully but when the statement response.data does not return the JSON data but it instead returns this;
Object { data: Object, status: 302, headers: headersGetter/<(), config: Object, statusText: "Found" }
Usually that statement would print out the data Object contained in the object above. What is going wrong?
var data = JSON.parse(apiResponse);
var name = data.response;
I have the following controller:
#RequestMapping(value = { "/member/uploadExternalImage",
"/member/uploadExternalImage" }, method = RequestMethod.POST)
public String handleFileUpload(#RequestParam("url") String url,
Principal principal) throws IOException {
File file = restTemplate.getForObject("url", File.class);
file.toString();
return null;
}
And I have the following ajax:
$.ajax({
url: 'uploadExternalImage', //Server script to process data
type: 'POST',
success: function () {
},
complete:function(){
$.fancybox.hideLoading();
},
// Form data
data: {url: files[0].link},
cache: false,
contentType: false,
processData: false
});
in spring log I see that
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'url' is not present
if I change ajax method with GET:
$.ajax({
url: 'uploadExternalImage?url=123', //Server script to process data
type: 'POST',
success: function () {
},
complete:function(){
$.fancybox.hideLoading();
},
error: function (data) {
},
cache: false,
contentType: false,
processData: false
});
it works fine
How does to configure spring correctly?
Http POST is capable of being used for request parameters on request body. But you are trying to use it on a different way.
Try this:
$.ajax({
type: 'POST',
url: "uploadExternalImage?url=BLABLA",
data: text,
success: function (data) {
//
}
});
If you want it on request body then use #RequestBody
I am trying to connect a Java REST service to a ExtJs JSONP request but even though the java method executes I haven't been able to get a response test. This is what I am trying:
Java Code:
#Path("/hello")
public class Hello {
#GET
#Produces("text/javascript") // have also tried application/json
public String sayJsonHello(#QueryParam("_dc") String dcIdentifier, #QueryParam("callback") String callback) {
System.out.println(callback);
callback += "({\"success\":true, \"msj\":" + "\"" + "Exitoooo!" + "\" });";
System.out.println(callback);
return callback;
}
}
ExtJs code:
Ext.data.JsonP.request({
url: "http://10.1.50.66:7001/Simulador/webresources/hello",
params: {
},
callback: function (response) {
console.log(response); //true
console.log(response.result); //undefined
console.log(response.responseText); //undefined
console.log(response.success); // undefined
if (response.success === true) {
Ext.Msg.alert('Link Shortened', response.msj, Ext.emptyFn);
} else { // entering here :( why ?
Ext.Msg.alert('Error', response.msj, Ext.emptyFn);
}
}
});
response is printting true, everything else undefined :(
callback looks like this Ext.data.JsonP.callback1({"success":true, "msj":"exito"})
Any ideas what could be wrong?
Ok this worked out for me:
Ext.data.JsonP.request({
url: "http://10.1.50.66:7001/Simulador/webresources/hello",
callbackKey: 'callback1',
params: {
},
success : function(response) {
console.log("Spiffing, everything worked");
// success property
console.log(response.success);
// result property
console.log(response.result);
console.log(response.msj);
},
failure: function(response) {
console.log(response);
Ext.Msg.alert('Error', 'Please try again.', Ext.emptyFn);
}
});
I am using jsp and jquery...and struts.I have a problem understanding the redirect to login page for ajax request.I tried to see request on browser on XHR tab and it gives me 302 status code in header.I am not able to comprehend how do i redirect.
My approach
1)The application has a function which checks if the user is signed in or not and has function to redirect to login url.
2)Else do some other processing.
How do I come back to same page after login.Is there any way?.....Also for redirecting on server side i am using Response.redirect()...Can someone explain how to catch response from server?...
function buttonpress(param1,param2)
{
$.ajax({
type:"GET",
data:{
X:param1,
Y:param2,
},
url:"/application",
success:function()
{
alert("success message");
}
error:function()
{
alert("error message")
}
});
}
Use the data parameter passed to the ajax success() callback. If a 302 was issued, the target URL would be available at data.redirect.
function buttonpress(param1,param2)
{
$.ajax({
type: "GET",
data: {
X:param1,
Y:param2,
},
url: "/application",
success: function(data, status)
{
if (data.redirect) {
window.location.href = data.redirect;
} else {
alert("success message");
}
},
error:function()
{
alert("error message")
}
});
}
you can try this
function buttonpress(param1,param2)
{
$.ajax({
type: "GET",
data: {
X:param1,
Y:param2,
},
url: "/application",
success: function(data)
{
var flag = data.trim();
if (flag) {
// success code
} else {
window.location.href = '/logout.do';
}
}
});
}