When I tried to parse this URL:
http://localhost:3000/torrent?previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
I was expecting route = 'torrent-item' (String), but FlowRouter router value is ["", "torrent-item"] (Array)
online - https://ts-vcompile.herokuapp.com/user#!/torrent?previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
repo - https://github.com/HedCET/TorrentSearch
There is one key route in queryparameter which has no value. So default value assumed is an empty string. It will always return you an array of keys with same name(in this case 'route').
So you will not get route = 'torrent-item'
previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
Your URL decodes as
http://localhost:3000/torrent?previous=/torrent?previous=%2Fuser&route=&route=torrent-item
cf: http://meyerweb.com/eric/tools/dencoder/
so you have &route=&route=torrent-item which will return ["", "torrent-item"] since route is there twice.
You just need to figure how to encode this URL properly to read it right.
If it's a URL you are reading from somewhere, then you need to parse the multiple arguments of the array to find what you want.
Related
I'm trying to make a get request to Firebase. In my url, I have to send the auth token which is very long (more than 900 characters). I create the url this way:
var url =
Uri.https('firebaseio.com', '/mydb.json?auth=$authToken&orderBy="userId"&equalTo="$userId');
But the url is not complete when I print it (the last characters are always lacking) and hence the request does not work. Anyone knows a solution for that?
Your URL isn't actually being cut. The print function can have a limit on its line length when being using in Flutter. Look elsewhere for your issue.
It likely has something to do with your misuse of quotes within your string. It's not normal to have quotes in your query parameters that are opened but not closed.
You can also improve this code by using the optional third queryParameters parameter of the Uri.https constructor to handle your query parameters:
var url = Uri.https(
'firebaseio.com',
'/mydb.json',
{
'auth': authToken,
'orderBy': '"userId"',
'equalTo': '"$userId"',
},
);
I need to pass base64 encoded string as a GET parameter, yes, I know that's a bad idea, but it is necessary. The problem is that I need it like so:
http://example.com/?data=c29tZXRoaW5nQA==
But it changed the URL to:
http://example.com/?data=c29tZXRoaW5nQA%3D%3D
Is there a way to do it? Adding this parameter via the query_vars filter fixed the URL, but then always returns the blog page not frontpage.
you can urldecode() your parameter, which will turn it back into the normal one, when you get it. –
So
$returnValue = urldecode('c29tZXRoaW5nQA%3D%3D');
Will return
$returnValue = "c29tZXRoaW5nQA==";
In short :
$theImage = urldecode($_GET['data']);
Should give you your disired string
http://127.0.0.1:8080/x?haha=1
I want to get something like ctx.QueryArgs().Get("haha")
is it possible in golang's fasthttp package?
Found it
ctx.QueryArgs().Peek("haha")
The naming choice is unexpected.
use Peek and PeekMulti
?haha=1
ctx.QueryArgs().Peek("haha")
?haha=1&haha=2
ctx.QueryArgs().PeekMulti("haha")
Some useful methods are declared here:
https://github.com/valyala/fasthttp/blob/a1cfe58ca86648c6701f1cb7e8b1587348dd5b9f/args.go#L245
You can retrieve a custom GET, POST PUT parameter using FormValue method:
- GET (Query String such as ?user=a&pass=b);
- POST, PUT body
Literally, from the documentation:
FormValue returns form value associated with the given key.
The value is searched in the following places:
Query string;
POST or PUT body.
There are more fine-grained methods for obtaining form values:
QueryArgs for obtaining values from query string.
PostArgs for obtaining values from POST or PUT body.
MultipartForm for obtaining values from multipart form.
FormFile for obtaining uploaded files.
token = string(ctx.FormValue("token"))
Documentation:
https://godoc.org/github.com/valyala/fasthttp#RequestCtx.FormValue
Another option while you don't have the ctx but have ctx.Request is this:
// somewhere
req := &ctx.Request
.
.
.
// somewhere else
req.URI().QueryArgs().Peek("somekey")
I am sending an url parameter to servlet using the following jQuery piece:
$.getJSON("http://localhost:8080/JsoupPrj/JasonGen?url=" + url, function(data) {
$("#content").html(data);
});
On the server side, the servlet gets the parameter, for that I coded as below:
String url = (String) request.getAttribute("url");
But it is not working, can you tell me where I am doing wrong? I believe I am not passing the parameter properly to the servlet. The servlet triggers each time through the JavaScript, but it is not seeing the parameters passed from the browser.
Here,
String url = (String) request.getAttribute("url");
you're trying to get a request parameter as a request attribute instead of as a request parameter. This will obviously not do what you want.
You need to get a request parameter as a request parameter, not as a request attribute.
String url = request.getParameter("url");
Unrelated to the concrete problem: you don't seem to be URL-encoding the parameter at all before sending. This will possibly cause other problems, unrelated to this one, when the url contains special characters. Look at the JS encodeURIComponent() function, or the data argument of the $.getJSON() function. See for more hints also How to use Servlets and Ajax?
I'm using the WebRequest class to make a request to some site. The query string contains a slash (/), which cause to the url to be cut by the site, because it doesn't see it as part of the query string.
The query string is: "my params / separated by slash".
The request:
var request = WebRequest.Create(
"http://www.somesime.com/q-my+params+%2f+separated+by+slash"
);
What I missing?
EDIT:
After all answers here are update:
I was wrong about query string, it's not actually query string, but the url should look (without "?"):
"http://www.somesime.com/q-my+params+%2f+separated+by+slash"
The url "http://www.somesime.com/q-my+params+%2f+separated+by+slash" is result of Server.UrlEncode method. The code:
var url = "http://www.somesime.com/q-" +
Server.UrlEncode(#"my params / separated by slash");
EDIT 2:
If I place the resulting url into a browser, everything works.
But if I run it through WebRequest class, the url results as it was called without "/ separated by slash" part
If this is your actual code you are missing the ?:
var request = WebRequest.Create("http://www.somesime.com/?q=my+params+%2f+separated+by+slash");
you forgot to put "?" before key name , so try :
var request = WebRequest.Create("http://www.somesime.com?q=my+params+%2f+separated+by+slash");
You need to have a look at apaches AllowEncodedSlashes option
http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes
You should be able to enable this through .htaccess or httpd_conf
UrlEncode it. (You will need a reference to System.Web )
string url = "http://www.somesime.com/?q=my+params+%2f+separated+by+slash");
var request = WebRequest.Create(HttpUtility.UrlEncode(url));
This part of the URL:
/q=my+params+%2f+separated+by+slash
is actually a continuation of the URL, the website probably uses some kind of URL routing. Query strings are denoted by the '?' and seperated by '&'.
If you did need to remove '/' from a URL then HttpUtility.UrlEncode would be the way to go, but this will not benefit you in your case as any encoding done to the URL will almost definitely cause your WebRequest to fail.
?
(Yes, that is what you are missing. :)
Use like this
$qrypic = 'INSERT INTO tbl_propics (userID,num,imagename,propic) VALUES ("$id","1","http://\graph.facebook.com/\$id/\picture?type=large","1")';