HTTP PUT with an array in parameters - http-post

I am trying to put an array (categories) in a http put url, but I always get an error. I can't find the correct syntax. I tried :
?name=test&categories=[1]
?name=test&categories=[{1}]
?name=test&array[categories]=1
...
Nothing works.
Is it possible to do it ?
Thanks

It depends on your REST implementation.
Usually there are three ways:
categories[]=1&categories[]=2&...
categories=1,2,3,...
categories=[1,2,3,...]
Better check your implementation documentation or debug your code if you can.

Related

How to send parameterId in the middle of http GET request url in Go [duplicate]

I am trying Golang for the first time. I am trying to call a GET REST API which has a path variable. I am using net/http for that. I am trying like below but no luck so far. I need to know how I can use the path variable and pass the variable from the code. Any help or code example would be highly appreciated.
This does not seem to work:
http.Get("http://127.19.0.1:8080/student/:id")
what about
http.Get(fmt.Sprintf("http://127.19.0.1:8080/student/%s", id)
?

Laravel route parameters don't care at all

I come from here:
Laravel pagination trouble with offset
Investigating into my code, I found that when a random alike parameter is given through a route, it will do an like query or I don't know, but it will still work as it will get the first part of the parameter:
The route I'm trying to "ensure" goes like this:
Route::get('/videos/cats/{race_id}/{cat_id}, [App\Http\Controllers\MeowController::class, 'getCatVideo']);
Can someone help me to get that exact parameter as integer, or prevent a route from working if the parameter is not exactly the given one?
Thank you in advance.
Parameters are required by default.
To validate parameter:
Route::get('/videos/cats/{race_id}/{cat_id}, [App\Http\Controllers\MeowController::class, 'getCatVideo'])
->where('race_id', '\d+')
->where('cat_id', '\d+');
Useful link: https://laravel.com/docs/8.x/routing#parameters-regular-expression-constraints

org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context

I have been using thymeleaf th:onclick attribute to call javascript function with parameters as below
th:onclick="|myFunction('${parameter1}')|"
But with thymeleaf 3.1.10 this has been removed. and they are suggesting to use th:data attribute.
I however found workaround on as below and both of them are working perfectly.
th:attr="onclick=|myFunction('${parameter1}')|"
th:onclick="#{myFunction('${parameter1}')}">
Now i am not sure if these workarounds are correct way to do things and if yes which one is the better way.
The first will work like you want -- however, you are bypassing the the security restriction and now your pages are vulnerable to javascript injection (which is the original reason this change was made).
The second one just plain doesn't work. It doesn't expand out the variable ${parameter1}, instead just encoding it as a url like this:
onclick="myFunction?$%7Bparameter1%7D"
You really should be doing it as shown on the page.
th:data-parameter1="${parameter1}" onclick="myFunction(this.getAttribute('data-parameter1'));"

Is it possible to pass multiple parameters in request url using webhdfs?

Is it possible to pass multiple arguments in url using webhdfs for instance like show below? http://112.128.0.17:9870/webhdfs/v1/user/myuser/file2.txt&file1.txt?op=DELETE&user.name=myuser&createflag=&createparent=true&overwrite=false&recursive=trueObviously it is just an example which doesn't work but maybe there is any way to do this? Or it is needed to send multiple requests?
The answer is no, besides the fact that the URL you created is not even valid.
You will need to issue one request (file operation) at a time.

How do I parse a POST to my Rails 3.1 server manually?

Scenario:
I have a Board model in my Rails server side, and an Android device is trying to post some content to a specific board via a POST. Finally, the server needs to send back a response to the Android device.
How do I parse the POST manually (or do I need to)? I am not sure how to handle this kind of external request. I looked into Metal, Middleware, HttpParty; but none of them seems to fit what I am trying to do. The reason I want to parse it manually is because some of the information I want will not be part of the parameters.
Does anyone know a way to approach this problem?
I am also thinking about using SSL later on, how might this affect the problem?
Thank you in advance!! :)
I was trying to make a cross-domain request from ie9 to my rails app, and I needed to parse the body of a POST manually because ie9's XDR object restricts the contentType that we can send to text/plain, rather than application/x-www-urlencoded (see this post). Originally I had just been using the params hash provided by the controller, but once I restricted the contentType and dataType in my ajax request, that hash no longer contained the right information.
Following the URL in the comment above (link), I learned the how to recover that information. The author mentions that in a rails controller we always have access to a request variable that gives us an instance of the ActionDispatch::Request object. I tried to use request.query_string to get at the request body, but that just returned an empty string. A bit of snooping in the API, though, uncovered the raw_post method. That method returned exactly what I needed!
To "parse it manually" you could iterate over the string returned by request.raw_post and do whatever you want, but I don't recommend it. I used Rack::Utils.parse_nested_query, as suggested in Arthur Gunn's answer to this question, to parse the raw_post into a hash. Once it is in hash form, you can shove whatever else you need in there, and then merge it with the params hash. Doing this meant I didn't have to change much else in my controller!
params.merge!(Rack::Utils.parse_nested_query(request.raw_post))
Hope that helps someone!
Not sure exactly what you mean by "manually", posts are normally handled by the "create" or "update" methods in the controller. Check out the controller for your Board model, and you can add code to the appropriate method. You can access the params with the params hash.
You should be more specific about what you are trying to do. :)

Resources