Jmeter-Regular expression extractor - regex

My Jmeter response returns me 'Location' in the response header.I want to fetch this Location header and use it on my other requests.
Sample Start: 2015-07-24 14:46:38 CEST
Load time: 163
Latency: 163
Size in bytes: 372
Headers size in bytes: 350
Body size in bytes: 22
Sample Count: 1
Error Count: 1
Response code: 201
Response message: Processed
Response headers:
HTTP/1.1 201 Processed
X-Backside-Transport: OK OK,FAIL FAIL
Connection: Keep-Alive
Transfer-Encoding: chunked
****Location: /retail/iows/ie/en/storage/servicedocs/paxplanner/2015-07-24/eCommerce.pdf****
X-Client-IP: 127.0.0.1,10.62.26.150
Content-Type: application/octet-stream
Date: Fri, 24 Jul 2015 12:46:38 GMT
X-Archived-Client-IP: 127.0.0.1
Steps I followed:
I have used Regular expression extractor.
Enabled response header radio button with the whole location header.
Please help me to sort it out.

If you want to retrieve the Location field's value from the request's response, you might want to try the following pattern: Location:([^\r?\n]+), the first matching group will contain the value of the Location field.
Above expression is based in the following rules:
HTTP header fields are colon (":") separated <key, value> pairs.
HTTP header fields are terminated by the EOL char combination (CR and LF)

Please try this..
Location:([\s\S]*)X-Client
If it doesn't work then try to use a \ before - in X-Client (escaping -)

Related

Remove HTTP headers from Prometheus in Zabbix

I have a server that has a Nginx VTS module installed on it, which outputs metrics in prometheus format.
When I try to actively check web.page.get via Zabbix I get the HTTP header and then the data in the format below:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 24 Sep 2020 09:16:20 GMT
Content-Type: text/plain
Content-Length: 33769
Connection: close
Vary: Accept-Encoding
# HELP nginx_vts_info Nginx info
# TYPE nginx_vts_info gauge
nginx_vts_info{hostname="example",version="1.18.0"} 1
# HELP nginx_vts_start_time_seconds Nginx start time
# TYPE nginx_vts_start_time_seconds gauge
nginx_vts_start_time_seconds 1600367492.145
# snip output...
I wrote a regular expression that removes the header but only outputs the first line:
# \n\s?\n(.*)
# HELP nginx_vts_info Nginx info
How do I rewrite the expression so that the header is removed and the rest of the data is available?
Please try below regex
\n\s?\n([\s\S]*)
in regex . wont check newlines unless specific flags set. hence in your example, only the first line was returned. so rewriting it to include newlines as well will help.

Filter data received from HTTP request

So in my c++ program i create a socket then download file from my web server (website) which retrieves a http response (using recv) then store response in char buffer, in this question let's say the buffer identifier is something like httpbufff, if i take httpbufff and cout it, it will look like this:
HTTP/1.1 200 OK
Date: Tue, 12 Jul 2016 08:52:15 GMT
Server: Apache/2.4.16
X-Powered-By: PHP/5.4.45
Vary: Accept-Encoding,User-Agent
Connection: close
Content-Type: text/html
Website content test
My question is, is there a way to extract "Website content test" from my char buffer httpbufff?
I was thinking about using strtok but that doesn't seem like a good solution in my opinion.
thanks!

CPPREST redirect location for response code 302

I am using CPPREST http_client to get a RSS feed from :
http://www.20min.ch/rss/rss.tmpl?type=channel&get=68
but I am receiving redirect response code : 302
When i check the body of the response it is :
Received response status code:302
response is [HTTP/1.1 302 Found
Age: 0
Connection: keep-alive
Content-Type: text/html
Date: Mon, 14 Mar 2016 06:30:48 GMT
Keep-Alive: timeout=30, max=100
Location: http://www.20min.ch/redirect?url=www.20min.ch:80
Server: Kaesebrot 1.23-rc1
....
Redirecting to http://www.20min.ch/redirect?url=www.20min.ch:80">http://www.20min.ch/redirect?url=
Now when I retry with URL received in location field of response i.e. http://www.20min.ch/redirect?url=www.20min.ch:80
I still get the same response of 302.
M I using the wrong redirect URL?
Also for finding the redirect url in CPPREST I could not find any direct method , I had to find the search the response body and find the substr.
I have also retried with :
http://www.20min.ch:80/rss/rss.tmpl?type=channel&get=68
but same 302 respone.
Kindly advice.
Location: http://www.20min.ch/redirect?url=www.20min.ch:80
looks like a cyclic redirect to me.

HTTP/1.1 401 Unauthorized in Response Headers in Load runner for GET Requests

I am new to Load runner , Am facing am issue while play back of the script
LR 12.50
O.S Windows 7 SP2
Protocol is Mobile HTTP/HTML
Recording mode is Proxy
Let me explain my scenario
While executing following function:
web_custom_request("authenticate",
"URL=https://ws-xx.xxx.com/tcs/rest/authenticate?include=user,company",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
"EncType=application/json",
"Body={\"password\":\"xxx\",\"username\":\"xxx\",\"version\":\"1.0.40\"}",
LAST);
For the above POST method , am getting response as below
HTTP/1.1 200 OK\r\n
Date: Tue, 13 Oct 2015 19:19:21 GMT\r\n
Server: Apache-Coyote/1.1\r\n
Content-Type: application/json\r\n
Set-Cookie: dtCookie=DBE9311E44E5C47902702DC762030583|TXlBcHB8MQ; Path=/;
Domain=.xxx.com\r\n
Connection: close\r\n
Transfer-Encoding: chunked\r\n
Which is fine ,Now the second custom request is shown below
web_custom_request("profiles",
"URL=https://ws-test.xxx.com/tcs/rest/profiles",
"Method=GET",
"Resource=1",
"RecContentType=application/json",
"Referer=",
"Snapshot=t2.inf",
LAST);
For the above GET requests in the replay logs am getting:
401 unauthorized error.
GET /tcs/rest/profiles HTTP/1.1\r\n
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT)\r\n
Accept: */*\r\n
Connection: Keep-Alive\r\n
Host: ws-test.xxx.com\r\n
Cookie: dtCookie=DBE9311E44E5C47902702DC762030583|TXlBcHB8MQ\r\n
\r\n
t=5921ms: 172-byte response headers for "https://ws-test.xxx.com/tcs/rest/profiles" (RelFrameId=1, Internal ID=2)
HTTP/1.1 401 Unauthorized\r\n
Date: Tue, 13 Oct 2015 19:19:22 GMT\r\n
Server: Apache-Coyote/1.1\r\n
Content-Type: application/json\r\n
Connection: close\r\n
Transfer-Encoding: chunked\r\n
\r\n
t=5922ms: 4-byte chunked response overhead for "https://ws-test.xxx.com/tcs/rest/profiles" (RelFrameId=1, Internal ID=2)
8b\r\n
t=5923ms: 139-byte chunked response body for "https://ws-test.xxx.com/tcs/rest/profiles" (RelFrameId=1, Internal ID=2)
{"errors":[{"message":"Authentication required to access endpoint","status":"401","code":"
NotAuthenticated","header":"Not Authenticated"}]}
I refereed this link.
My understanding from the above custom request , login is success but the next
subsequent requests are getting failed.
I have used web_cleanup_cookies() function but didn't solve the issue .
I tried to capture the Cookie ID using the below function
web_reg_save_param("COOKIE_ID",
"LR= Cookie: dtCookie=" ,
"RB= |TXlBcHB8MQ\r\n",
"Ord=All",
"RelFrameId=1",
"Search=All",
LAST);
web_add_header("Cookie",lr_eval_string("{COOKIE_ID}"));
Now question is where to place parameter "COOKIE_ID" in my script while there is
no value in script for COOKIE_ID?
How to handle this issue ? Can anybody please help me .
Please add below headers to the script
web_set_sockets_option("SSL_VERSION","TLS");
web_set_user("username", "password", "domain:portno" );
web_set_sockets_option("INITIAL_BASIC_AUTH","1");
In Vugen, Select snapshot view and compare both record and replay requests, suspecting there might be a missing of header in replay request.
If cookie is the only thing changing you can add it by using web_add_cookie function.

Multipart/form-data request to Drupal 7 REST server/Services module returns FALSE with 200 status code on file upload

I have been working for the last couple of days trying to get a file upload to my drupal REST Server and I feel like I am close but I am getting a somewhat confusing 200 status code with a response of "false". I am a total http-request novice so I have been having some trouble. Here is what my http-post looks like:
POST /?q=rest/file HTTP/1.1
Host: localhost:8888
Language: en-us,en;q=0.5Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Connection: keep-alive
Accept-Charset: ISO-8859-1,utf-8
Cookie: SESSdc0685ed01f285dab628a3700259e6bc=UAdNJUsQL5TpqEXIWFtXEcLw3wooEwqW9e0JxSz2ZHw
Content-Length: 389
Content-Type: multipart/form-data; boundary=---------------------------1137522503144128232716531729
-----------------------------1137522503144128232716531729
Content-Disposition: form-data; name=\"file\"; filename=\"empty folder.zip\"
Content-Type: application/zip
..
encoded content here
..
-----------------------------1137522503144128232716531729--
And the response I get is simply "false with a header that looks like this:
(("Content-Type" "application/json") ("Connection" "Keep-Alive") ("Keep-Alive" "timeout=5, max=100") ("Content-Length" "5") ("Vary" "Accept") ("ETag" "\"1328910809\"") ("Cache-Control" "no-cache, must-revalidate, post-check=0, pre-check=0") ("Last-Modified" "Fri, 10 Feb 2012 21:53:29 +0000") ("Expires" "Sun, 19 Nov 1978 05:00:00 GMT") ("X-Powered-By" "PHP/5.3.6") ("Server" "Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6") ("Date" "Fri, 10 Feb 2012 21:53:29 GMT") ("Status" "HTTP/1.1 200 OK"))
and status code 200. Also, the file is does not actually show up in the Drupal file system. Could the problem be that I need to specify where to put it? I snooped the http-post from the actual Drupal form and it looks almost identical to my post accept it has many more pieces of content.