I have an app that I am trying to load test with JMeter, and I am unable to extract a value from an URL, that is generated after HTTP POST.
The app flow (simplified) goes something like this, with corresponding URLs:
Login: http://host:port/login
Go to Dashboard (HTTP GET): http://host:port/dashboard
Click "Create Content" (HTTP GET): http://host:port/$string1/$string2=/create
Enter data, click "Submit" (HTTP POST) now URL is: http://host:port/$string1/$string2=/content/$string3
$string1, $string2 & $string3 are randomly generated; $string1 & $string2 are available in the body at the dashboard URL (which are easily extracted using regex); $string3 however is returned after content is created. I need $string3 at Step 4 above to view the newly created content, and proceed with next steps in my script.
I don't have access to the internals of the app or the server it is on.
Sanity check:
Is this a chicken-egg situation?
Or am I missing something in JMeter?
Any way around this problem?
I assume after you click "submit" it's a post request that will start the create content process, then get a redirect reply from the server. (you can verify if it's a redirect reply in tree view)
Uncheck the redirect option in Jmeter and add a regex extractor element to the same request.
Then extract the redirect URL with something like Object moved to <a href="/(.+?)">here and in the next HTTP request element you can use that extracted as variable to Path like ${string3}!
Related
I'm using node-http-proxy to run a proxy website. I would like to proxy any target website that the user chooses, similarly to what's done by https://www.proxysite.com/, https://www.croxyproxy.com/ or https://hide.me/en/proxy.
How would one achieve this with node-http-proxy?
Idea #1: use a ?target= query param.
My first naive idea was to add a query param to the proxy, so that the proxy can read it and redirect.
Code-wise, it would more or less look like (assuming we're deploy this to http://myproxy.com):
const BASE_URL = 'https://myproxy.com';
// handler is the unique handler of all routes.
async function handler(
req: NextApiRequest,
res: NextApiResponse
): Promise<void> {
try {
const url = new URL(req.url, BASE_URL); // For example: `https://myproxy.com?target=https://google.com`
const targetURLStr = url.searchParams.get('target'); // Get `?target=` query param.
return httpProxyMiddleware(req, res, {
changeOrigin: true,
target: targetURLStr,
});
} catch (err) {
res.status(500).json({ error: (err as Error).message });
}
}
Problem: If I deploy this code to myproxy.com, and load https://myproxy.com?target=https://google.com, then google.com is loaded, but:
if I click a link to google images, it loads https://myproxy.com/images instead of https://myproxy.com?target=https://google.com/images, also see URL as query param in proxy, how to navigate?
Idea #2: use cookies
Second idea is to read the ?target= query param like above, store its hostname in a cookie, and proxy all resources to the cookie's hostname.
So for example user wants to access https://google.com/a/b?c=d via the proxy. The flow is:
go to https://myproxy.com?target=${encodeURIComponent('https://google.com/a/b?c=d')}
proxy reads the ?target= query param, sets the hostname (https://google.com) in a cookie
proxy redirects to https://myproxy.com/a/b?c=d (307 redirect)
proxy sees a new request, and since the cookie is set, we proxy this request into node-http-proxy using cookie's target.
Code-wise, it would look like: https://gist.github.com/throwaway34241/de8a623c1925ce0acd9d75ff10746275
Problem: This works very well. But only for one proxy at a time. If I open one browser tab with https://myproxy.com?target=https://google.com, and another tab with https://myproxy.com?target=https://facebook.com, then:
first it'll set the cookie to https://google.com, and i can navigate in the 1st tab correctly
then I go to the 2nd tab (without closing the 1st one), it'll set the cookie to https://facebook.com, and I can navigate facebook on the 2nd tab correctly
but then if I go back to the first tab, it'll proxy google resources through facebook, because the cookie has been overwritten.
I'm a bit out of ideas, and am wondering how those generic proxy websites are doing. Ideally, I would not want to parse the HTML of the target website.
The idea of a Proxy is to intercept the client requests, either by ports or by backend APIs, extract the URLs of requested resources, modify them and make those requests by self from servers, and modify responses and send them back to the client.
your first approach does this except modify responses and send back modified responses.
one way to do this is to edit all links in resources return by proxy to have your web address in them, only then send them as responses back to the client.
another way is to wrap the target site in a frame, as most web proxy sites do, and have a script to crawl the page and replace all links.
there is a small problem though. javascript-based requests are mostly hardcoded in the script and it is not an easy job to replace them.
your seconds approach sounds as if it would work better, but just a sound, nothing concrete I can say. implement a tab activity checker so you can change the cookie to your active tab. please check how-to-tell-if-browser-tab-is-active discussion about that
I have two thread groups in my project, and on of them has two HTTP request samplers. It's set up like the following
Thread group
Timer: Random between 1 and 5 minutes: ${__Random(60000,300000)}
HTTP request: A basic GET web service call
HTTP request: A basic GET web service call
Here's the Thread group setup.
That's it. Here's an example of the web service call setup
And here's what the "Statistics" portion of the HTML report looks like. Note the -1, -2 after the HTTP Request names. I'm trying to figure out why that's happening.
My other thread group / samplers are not displaying that way, but they're set up the same way, as far as I can tell.
In your example, HTTP requests Get Locations-0, Get Locations-1 are sub requests of Get Locations which appeared since you have selected the check box - Follow Redirects.
In case, you don't want HTTP requests Get Locations-0, Get Locations-1 to appear in your HTML report:
In the listener page(where you have saved the result file; which is the source file of HTML report) -> click on configure button -> uncheck the Save Sub Result option
You can also refer :Configure result file to customize HTML report
Turns out that some of the calls were returning a 200, others a 301, that's where they got separated out, even though the 301's didn't register as errors in the report.
I need to hit a post request to an API service which requires a session id along with other parameters in its post request field in order to get the required information.
I am using Postman to test this API.
I would like to know how to send a 'session id' in a post request when using Postman?
I am aware of pre-request script in Postman, but I am unaware of how to use the variable in post request.
In Postman native app:
Turn on the Interceptor.
Go to Headers
Key: Cookie
Value : sessionid=omuxrmt33mnetsfirxi2sdsfh4j1c2kv
This post is bit old but I want to still answer incase someone else is looking for an answer.
First, you need to see if intercepter is enabled in the toolbar, it is present one step away from sign-in
If does not not get enabled when you click on it, you can install extension. I think there is one for Chrome. Go ahead and add the extension.
After that you can go back to Postman and enable intercepter
You will be able to see cookies in postman and at this point you can add _session_id
I hope this will help.
Thanks,
Hit inspect on the site you are working on, when logged in
On your Chrome/browser, go to application - cookies.
Copy your PHPSESSID.
On postman headers Key: Cookie
Value: PHPSESSID=dsdjshvbjvsdh (your key)
For standalone Postman app
You can use global variables in postman. First in the Tests tab of the first request set the session as global variable:
var a = pm.cookies.get('session');
pm.globals.set("session", a);
It might be 'session_id' as well (check in the headers of your first request) instead of session. To check if this variable is set, after you do your first request, go to the gear icon and click on globals.
Then go to your second request -> Headers and for key add 'Cookie' while for value add 'session={{session}}'
Side note: be careful not to save keys that are used by your framework or they might be deleted for some reason.
On your browser:
Open the developer tools (right click and Inspect).
Go to Application Tab > Storage > Cookies.
Open your site Cookie and copy the Name and Value.
In Postman 8+:
In your Request tab, go to Headers.
Click in the eye icon to see the hidden headers.
Click in the "Cookie" link that is in the top right corner.
In the "Manage Cookies" popup, select your domain, click on "+Add" button, or edit the existent cookie.
Paste the values that you copy from the browser. The complete value will look like PHPSESSID=f20nbdor26v9r1k5hdfj6tji0p; Path=/;
Click on "Save", and close the popup.
Select Tests Section below the Request URL
if(postman.getResponseHeader("authorization")!==null)
{
postman.setGlobalVariable("token","Bearer " + postman.getResponseHeader("authorization") );
}
Here u can use SessionId to get SessionId from Header and put in global variable .
I fire an image tag when someone converts on our website for reporting and analytics:
<img src="https://example.evyy.net/conv/?somechannel=cats&cid=3790&oid=123&cat1=premium&sku1=123&qty1=1&amt1=456&custid=qbc" />
We noticed traffic decline yesterday. To debug I visited the site and signed up, with the console open network tab.
I typed "evyy" into the filter box and I see 3 line items for my tag.
What does this mean? Should there not be just 1 line item? One item has a 302 status and the other two a status of 200. That's good right?
Screen attached. Does this look "right"? Is there any drill down in the network tab I can look at to see if there is a problem on our end with tracking?
"Initiator Other" usually means the network request was made from a user, not from Chrome, a redirect or a script.
The request was fired when someone clicked a button (this is what your analytics is probably tracking). You can read more about this in the Chrome DevTools docs.
Initiator: The object or process that initiated the request. It can have one of the following values:
Parser - Chrome's HTML parser initiated the request.
Redirect - A HTTP redirect initiated the request.
Script - A script initiated the request.
Other - Some other process or action initiated the request, such as the user navigating to a page via a link, or by entering a URL in the address bar.
The requests are made in the order you see, the first received the 302 response which said, "hey, go to this new url". That's (probably) why the second request was made, which got the 200. The third was probably from clicking on the button too. Looks fine to me.
I noticed another case not related with a user action:
<link rel="icon" type="image/jpeg" href="image.jpg" />
... causes the image.jpg to get loaded with "Initiator Other" (also true with images of another format).
(wanted to add this as a comment under the previous answer, but I am not allowed to)
One case where initiator type is 'other' is when a request gets redirected, in this scenario the redirected request will have initiator as other.
For Example: request was made for url1 which got redirected to url2, now in case of url2 we get initiator type as 'other'
I'm working on ASP.NET MVC3 with C#.
What is difference between Response.Redirect("http://www.google.com"); and Response.Write("REDIRECT=http://www.google.com");?
The difference is that the first will replace the response with a redirection page and end the execution, while the second will just write the text to the response stream and continue with creating the rest of the page.
Response.Redirect() sets an HTTP 302 header along with the URL to be redirected to.
Response.Write("REDIRECT=http://www.google.com"); will write that string to the response body, as in that redirect text would be appended to the HTML of your web page.
This will create the correct full HTTP Header for you:
Response.Redirect("http://www.google.com");
You have the ability to set or change some paramters for the HTTP Header.
HttpResponse Class
e.g set HTTP Status Code 404 or 500 or in your case 302 for redirect.
e.g set the HTTP Mime-type for jpg
Will write into the Body in your response..like a string output
Response.Write("REDIRECT=http://www.google.com");
The methods in question are quite self explanatory :)
Response.Redirect("http://www.google.com");
The Redirect will redirect you to another page, in the case it will take you to Google's home page.
Response.Write("REDIRECT=http://www.google.com");
The Write method will write a string of text to the web page. In this case it will write the text "REDIRECT=http://www.google.com" to your web page.
Play around with these 2 methods in your web project and see what happens.