I'm trying to send value in laravel controller using postman but it send null value.
UserController:
Route:
Postman:
There is no problem in get method
I am not sure which one are you accessing since you set the value in header but your variable named input. So, I will just provide both methods since it should be helpful!
There are two different method for accessing the body of the request or accessing the header of the request
Accessing the header request
$val = $request->header('val');
Accessing the body request
$val = $request->input('val');
Related
I have a search form in laravel and I want to save filtered values in cookie in laravel.
I have followed the laravel tutorial and tried to set cookie like this :
$request->cookie('name', json_encode($_POST), 84600);
But it is not saving cookie
Using the cookie method on the request is only for retrieving a value.
If you want to add a value to the upcoming response you can use the queue() method with the cookie() helper function:
cookie->queue('name', json_encode($_POST), 84600);
Using javascript try
$.cookie("name", JSON.stringify($("#youcookiesId_hidden filed").data()));
How can I read a JSON request?
$request->all(); //Uncaught ErrorException: Array to string conversion
This does not work.
$request->('title');
This works and gets the title param.
But how can I get the entire data set?
After some googleing I see there was once a method called:
$request->json()->all();
But this no longer appears to work.
Try doing this
dd(request()->all());
Since $request is an object of Request class, there is no property for $request->all()
"When sending JSON requests to your application, you may access the JSON data via the input method as long as the Content-Type header of the request is properly set to application/json.
You may even use "dot" syntax to dig into JSON arrays:"
$name = $request->input('user.name');
https://laravel.com/docs/5.5/requests#retrieving-input
In Jmeter, how to use AUTH “access_token” for passing through header for another POST request ? Below are the step that i have done but it's not working ... How to use "access_token" value, that will use another post request dinamically ? Attached issues is here...
enter image description here
You need to add jp#gc-JSON Path Extractor in HTTP request, the particular HTTP request which is generating access token in its response data .
If response is like - {"access_token":"f5b06970-f00f-4b44-89c8-305738e19cba"}
In JSON path extractor add
Variable name - access_token (variable in which access_token will be stored)
2.JSON Expression - $.access_token (this will varry according to json response)
3.Default Value - NOT_FOUND
Now the next step is to use this variable named "access_token ". You can use it in your HTTP request for which you need to pass access token under HTTP header manager as access_token = ${access_token }
below link will help you a lot:
https://www.blazemeter.com/blog/advanced-usage-json-path-extractor-jmeter
How can I customize $http in angularjs such that it will accept strings as its response in a $http.post call? Right now, when I do a $http.post call, my response is in string but angularjs by default uses JSON therefore I get an error. Right now I have something along the lines of
function getResponseURL(response) {
//this will convert the response to string
return response;
}
$http.defaults.transformResponse = [];
$http.defaults.transformResponse.unshift(getResponseURL);
However if I use the code above, any $http.post calls after that call uses string. I want it to use the original default JSON format. How can I go about into just temporarily changing the response to string for this one call but the rest stay as JSON type as a response?
Why not only register that transform for ONLY that request?
Angular js $http docs
If you wish
override the request/response transformations only for a single
request then provide transformRequest and/or transformResponse
properties on the configuration object passed into $http.
How do I send an element of type object via ajax to a servlet?
In the ajax I am passing the value as follows below:
data: { mapList : mapLists }
To get the value in the Servlet am doing follows below:
Object o = request.getAttribute("mapList");
System.out.println(o);
However, the returned value is always null. What should I do to get around this problem?
Change your ajax datas by :
data: { 'mapList' : mapLists }
On HTTP GET or POST requests you can only send a list of key/value pairs as parameters to the server so you will have to manually serialize your object to send its attributes in this format.
You should better use HttpServletRequest.getParameter(String) in place of HttpServletRequest.getAttribute(String). Also, what you get as an HTTP GET/POST parameter will always be received in the servlet as a String.
I assume that you are using jQuery to send the ajax request. I also asume that your mapLists variable is a json object. As far as I know, jQuery doesn't automatically convert a json object to a key/value pair HTTP parameter list so you will have to do it by yourself and then parse it back in the servlet. You can use JSON.stringify() to convert your json object or you can serialize it manually.