Get a request parameter key-value in fasthttp - http

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")

Related

Wordpress encodes GET parameter

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

Using a substring of a return value in a subsequent request

I'm attempting to construct a series of Paw calls using the variables feature. I have one situation I'm unable to solve.
At authentication into the server I'm using, I get a JSON response, with one value that looks like this:
endpoint = "https://sub.something.com/thingone/thingtwo.php?token=sometoken&id=blahblah"
The endpoint portion "https://sub.something.com/" is then used as the base for subsequent calls, where a call might be "GET https://sub.something.com/data?id=123".
I don't want to hardcode the endpoint in Paw, as the endpoint will vary based on factors I can't predict at my end.
Is there a way to do basic string processing like this either in Paw, or by calling out to a shell script and using the return value of said script as a Paw variable?
That's doable using that RegExp Match dynamic value extension. Click on that previous link and hit Install Extension.
Type "Regexp" in the field you expect this value to be used. Pick Regexp Match from the completion results:
Then enter a regexp that matches your need, https?://[^/]+/? should be good:
I've put your example string in the screenshot above to show that it works, but you can instead put a "pointer" (Response Dynamic Value) to the response you want:
In the choices, pick Response Parsed Body if you want to parse a JSON or XML from the reponse. If the string is simply in plain text in the response body, pick Response Raw Body.
Once these steps are completed, you've got a working "Pointer" + "Parser" to the response that extract the part of the string you need. You can do the same operation with another regex for the token…
Tip: these dynamic value tokens can be selected like text and copy/pasted (Cmd+C/Cmd+V) :-)

how to get query parameter in lua or nginx?

I am trying to implement this-
https://gist.github.com/MendelGusmao/2356310
Lua,nginx based URL shortener,The only change i want to implement is when some query string parameter comes with shortened URL i need to take that parameter and insert into the long URL.
e.g.
http://google.com?test=2 will be like http://abc.in/abc
while hitting on http://abc.in/abc?test=3 I get redirected to - http://google.com?test=3.
For that i need to take query string parameters from $request_URI, can any one help with some code?
You should be able to use ngx.var.arg_name where name is the name of the query parameter you want to access. See Variables with Infinite Names section in this tutorial for details on query parameter handling; you may also check my blog post for Lua nginx/openresty examples.
As an alternative, you can use ngx.req.get_uri_args() to retrieve all query parameters as one table. See this section in the same tutorial for the brief comparison between these methods.
You can also use ngx.var.QUERY_STRING to access the query string and unescape and parse it.
You can obtain the query parameter with just nginx by using $arg_test, test is the name of the query parameter in this example.
This is documented in http://nginx.org/en/docs/http/ngx_http_core_module.html#var_arg_.

How to get POST and GET data from a FORM in ASP.NET

I need to get an understanding about how you can handle get and post data in a form in asp.net in these 2 situations:
You submit a form with GET method:
action: "form.php"
parameters: text1=test
You submit a form with POST method:
action: "form.php?text1=sometext"
parameters: text1=somedifferenttext
I know these 3 commands:
String val1 = Page.Request["text1"];
String val2 = Page.Request.Form["text1"];
String val3 = Page.Request.QueryString["text1"];
I wonder what are the exact commands to access get and post variables directly?
Get variables are stored in the query string:
String getText1 = Page.Request.QueryString["text1"];
Post variables are stored in the form:
String postText1 = Page.Request.Form["text1"];
If you want to know more about the difference between Get and Post variables, I'd suggest having a read of this question: When do you use POST and when do you use GET?
For a GET, Page.Request.RawUrl will get you the original querystring. You need to parse the whole URL to get it.
If it's a POST, read it from Page.Request.InputStream
It might also be useful to know that both Page.Request.Form and Page.Request.QueryString are NameValueCollection objects. So if you want to iterate over their keys, you can use Page.Request.Form.Keys and Page.Request.QueryString.Keys.

How do we send data via GET method?

I am creating a HTTPS connection and setting the request property as GET:
_httpsConnection = (HttpsConnection) Connector.open(URL, Connector.READ_WRITE);
_httpsConnection.setRequestMethod(HttpsConnection.GET);
But how do I send the GET parameters?
Do I set the request property like this:
_httpsConnection.setRequestProperty("method", "session.getToken");
_httpsConnection.setRequestProperty("developerKey", "value");
_httpsConnection.setRequestProperty("clientID", "value");
or do I have to write to the output stream of the connection?
or do I need to send the Parameter/Values by appending it to the url?
Calling Connection.setRequestProperty() will set the request header, which probably isn't what you want to do in this case (if you ask me I think calling it setRequestHeader would have been a better choice). Some proxies may strip off or rewrite the name of non-standard headers, so you're better off sticking to the convention of passing data in the GET URL via URL parameters.
The best way to do this on a BlackBerry is to use the URLEncodedPostData class to properly encode your URL parameters:
URLEncodedPostData data = new URLEncodedPostData("UTF-8", false);
data.append("method", "session.getToken");
data.append("developerKey", "value");
data.append("clientID", "value");
url = url + "?" + data.toString();
HTTP GET send data parameters as key/value pairs encoded within URL, just like:
GET /example.html // without parameters
GET /example.html?Id= 1 // with one basic parameter
GET /example.html?Id=1&Name=John%20Doo // with two parameters, second encoded
Note follow rules for character separators:
? - split URL in two pieces: adddress to left and paremeters to right
& - must be used to separate on parameter from another
You must know your platform specific native string encode function. Javascript uses escape, C# uses HttpUtility.UrlEncode
Yep, headers and properties are pretty much all you can send in a GET. Also, you're limited to a certain number of characters, which is browser dependent - I seem to recall about 1024 or 2000, typically.

Resources