Extract a string from Response Body in Jmeter - parsing

I am trying to set up an automated test in jmeter. However I am having a problem extracting a string from an array of numbers that are returned from an api call.
Currently Im recieving [1069936,1069931,1038673,1059014,1061326,1074842,1076998,1069605,1060567,1063853,2021064,2024239,1074835,1075227,1076997,1078435] but i would like to extract "1069936" and use it in the next api call. Ive tried -1 in the Match No. column of the Json Extractor but cant find any documentation to help.

Use JSON Extractor Post Processor as a child of Sampler Returning JSON Response.
Note : -1 will capture every matching possible. So use -1 when you want all the matches for that particular expression. Here you need the first match and not all matches.

Related

Question about using API to retrieve cell data

I’m wondering if someone could help me figure out a little issue I’m having. I’m trying to create an iOS shortcut to retrieve specific cell data from a Google Sheets document, and I’m really close, however, I’m hitting this snafu.
For my example, the data entered into the specific cell is: “0+ 5” (without the quotes).
I’m using the following URL to grab the data (with my string ID and API keys X’d out):
https://sheets.googleapis.com/v4/spreadsheets/XXXXXXXXXX/values/Sheet1!D#?key=XXXXXXXXXXXXXXXXX
(Also, the # character after “Sheet1!D” is purposeful….I have shortcuts configured to replace that character with a number I input when running the shortcut)
Anyway, the result I’m getting is:
{"range":"Sheet1!D99","majorDimension":"ROWS","values":[["0+ 5"]]}
Notice the “0+ 5” near the end, which is the data entered in the specific cell.
I know I can mess around with Regex to to have the shortcut specifically match that part of the text, but I’m assuming there’s a way to format the API URL so that it only gives me the data entered — in this case, only
0+ 5
and not all of the other info….am I correct in that assumption? If so, I’d rather go that route and have the shortcut be a bit less convoluted.
Thanks!
Server's response is in JSON format, meaning, you can use action Get Dictionary From Input and next use action Get Dictionary Value. Type in values for the key.
Check this image:
Hope this helps.

How to access body in luasocket as binary data?

This code:
local client = require("socket.http")
local resp = client.request("some_server.com/some_image123.png")
How do I get the body -- as binary data / image -- of a response? Here "resp" isn't that.
You know, had you read the manual, you'd know this:
If successful, the simple form returns the response body as a string, followed by the response status code
I'll give you the benefit of the doubt and assume you really didn't know where to find that information, but even a quick google search for "luasocket reference" would have brought that page up.
EDIT: Or maybe you already knew that, and instead didn't realize that a string in Lua is also a representation of binary data. Same as in any other language, Lua strings are just arrays of bytes under the hood, but other than, for example C, they can contain any byte, including 0x00, so you can use them to store any sort of binary data you want.

How to translate multiple words/sentence through Baidu

I am developing an application in iOS where I need to add a functionality to switch the application language in Chinese/English.
I am using Baidu API to achieve this. I am able to translate single world or complete one sentence. But suppose my has multiple text which I need to place at diff location then either I have to hit the API multiple times or by wrapping all into one API.
I have followed their documentation but nothing seems work.
As per their documentation.....
1. How do I translate multiple words or more text in a request?
You can use the newline (in the majority of the programming language for the escape symbol \ n) in the sent field q to separate the multiple words or pieces of text to be translated so that you can get multiple words or multiple text independent translations The result. Note that before sending the request to the q field do URL encode!
And I am trying to get the result for this....
appid = 2015063000000001 + q = apple + salt = 1435660288 + key = 12345678
Let me give an example: Suppose I need to convert two different word. “apple” and “mango”
2015063000000001+apple\ nmango+1435660288+7_8ogRLnl7PO52O0UYd2  
2015063000000001apple\n mango143566028812345678 (Get the MD5 = c0610b314af72e42a4a5b9e62757faf7)
http://api.fanyi.baidu.com/api/trans/vip/translate?q=apple\nmango&from=en&to=zh&appid=2015063000000001&salt=1435660288&sign=c0610b314af72e42a4a5b9e62757faf7
When I am hitting above url on chrome then getting this result.
Result : {"error_code":"54001","error_msg":"Invalid Sign”}
Now I got the answer for my question.
In URL replace "\n" with URL encode "%0A".
Also generate MD5 via the code not from online.

biopython qblast function no data returned

I'm trying to blast an 8-mer (string of length 8) against the NCBI database. However, whenever I use qblast, it comes up empty with respect to matches. This is my code:
from Bio.Blast.NCBIWWW import qblast
import Bio.Blast.NCBIXML as parser
a = qblast('blastp','nr','GGMPSGCS')
b = parser.read(a)
print b.alignments`
Whenever I do this, it just prints the empty list []. Why is this happening? Can anyone shine a light on it?
I can get a match using the NCBI online BLAST tool, and I can even get a match if I use a longer kmer like "SSRVQDGMGLYTARRVR". It just happens that all the 8-mers I search come up empty.
From the FAQ at http://biopython.org/DIST/docs/tutorial/Tutorial.html
Why doesn’t Bio.Blast.NCBIWWW.qblast() give the same results as the NCBI BLAST website?
You need to specify the same options – the NCBI often adjust the default settings on the >website, and they do not match the QBLAST defaults anymore. Check things like the gap >penalties and expectation threshold.
Check that qblast is using the same defaults, if not sure, make them explicit. I wouldn't be surprised if it's doing some sort of "read to short" filtering step.
As in this answer, you have to fine-tuning the qblast to override the defaults. The WWW frontend of NCBI-BLAST automatically adjusts your parameters to match the short (8 bp) sequences, but if you do it through Biopython API you have to do it manually.

Base64 encode: Three different outputs from different tools?

I am trying to verify an OAuth signature generated in code against a "known reputable source". All my steps are verified correct except the last, wherein a 'base signature string' is HMAC-SHA1 hashed against a secret key and then base64 encoded.
I have confirmed that my hash value is the same as expected by the algorithm. I then disconfirmed that my base64 encode was the same. Attempting to determine why my encode failed, I wanted to check the encoder I was using.
Here is the (hash) string being base64 encoded:
203ebb13a65cccaae5cb1b9d5af51fe41f534357
Here is the base64 encode that results in my code:
MjAzZWJiMTNhNjVjY2NhYWU1Y2IxYjlkNWFmNTFmZTQxZjUzNDM1Nw==
According to http://www.motobit.com/util/base64-decoder-encoder.asp, that is the correct result:
But, according to http://www.online-convert.com/result/096d7b00138f3726daee5f6ddb107a62 (provided with the secret and base string, not the hash), a different base64 should have been output. Note that the hash output is my correct hash despite the difference in base64:
Finally, the "official" tester (http://hueniverse.com/oauth/guide/authentication/) outputs a third different base64 from the same hash:
I have no idea what I'm doing wrong, and the fact that these tools are outputting different results makes me wonder if there is in fact such a thing as base64 encoding or if they are actually using different algorithms? Perhaps the fact that it's for OAuth would help you help me identify the answer.
Thanks for any leads from the wise.
OK, in this case the first website was making the same "mistake" I was (in my case it was a mistake, the first website may just be making an unstated assumption).
That mistake is whether the hash is interpreted as a string (which gets base64encoded) or as a series of hexadecimal values which get base64encoded. In the former case, the resultant encode is longer than the original string, while in the latter the resultant encode is shorter than the original string. This is not only empirically true but the interwebs show that it is one of the concepts behind the standard in the first place.
The second website, working from (as stated) "hex" data, got the correct answer.
Try to check via https://base64-encode.org
On this website you can convert all types of images to Base64 string.

Resources