How to pass dynamic headers to the Http Request in jMeter? - http

There is a initial request going to the server which should retrieve the CSRF token and use that token id in post request header.
if that does not happen any POST requests to the server will return that error.
In the above screen shot, where token is the request to get the CSRF token Id, If I run the test this will generate one dynamic random token ID. But I need to pass the generated token ID in the post request through Header Manager. How can it possible. If yes, Can any one suggest some way to do that.

I resolved it by using User defined variables and Regular Expression Extractor to pass the parameters from one request sampler to another.

In the firs request add a postprocesor of the request. if the response is un json format user json Extractor, in json Extractor define a variable that read the token
In the second request add a header Manager an refer varaible declare in json Extractor in the following way in value cell, ${variable}

Related

Camel how to bypass request header from entering to http dsl component request?

I'm having a following problem with camel http requests. I would want to preserve a value of url query string parameter without passing it to another http request that needs to be done on the route. The value is needed after the http request to external api to process the data. Below is a clarification of the problem:
rest("/api")//We get requests as /camel/api?param1=xyz...
.get()
.route()
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.setHeader("Accept-Encoding", constant("gzip"))
.setHeader("Accept", constant("*/*"))
.removeHeader(Exchange.HTTP_URI)//Remove this
//How do I prevent the {header.param1} from being passed to the following http request but still be able to use it after the request on the route?
.to("https://someapi.org/api/...")
//To process the result, we need the original {header.param1} value from the request to this /camel/api endpoint
.endRest();
What is the correct way to achieve this?
If you receive parameters that are only needed in the current route and should not be passed on to any other endpoints, you can also copy them over to Exchange properties and delete the headers.
In contrast to message headers, the Camel Exchange properties are not propagated to routings and they are removed together with the Exchange when the message reaches an end of the current route.
.setProperty("param1", header("param1")) // create property from header
.removeHeader("param1") // remove the header
This is a very explicit and transparent way to do this, but you have to do it everywhere you need it. So it is good for exceptional cases that you want to make explicit.
On the other hand a HeaderFilterStrategy prevents sending specific headers (based on patterns) to the endpoints you configure it. So it is very good for general header rules you want to apply to all endpoints of a specific type (for example to all HTTP endpoints).

SAP CPI HTTP Post how to pass token

I need to send a POST in CPI to a s4hana service, and in order to pass it directly in JSON, not in xml, I want to use the simple HTTP adapter.
How can I get the token with a GET and use it with a POST afterwards?
do the GET, parse the XML and save the token as a variable in message header.
Use the message header variable in your POST via filling the JSON with ${header.yourVariableName}
see this:
https://blogs.sap.com/2018/01/18/sap-cpi-clearing-the-headers-reset-header/
http://blog.whint.de/runtime-variables-cpi/

Overriding HTTP request headers via query string

We have a client of a ServiceStack service that cannot easily send the correct value for some request headers (such as Accept or Accept-Encoding).
Is there any mechanism in ServiceStack (or ASP.NET) that can allow the client to use query string parameters to override the value of request headers, in a generic way?
The format URL param recognized by ServiceStack is close, but it seems to not help in this specific case (the client needs to send Accept: image/png, which seems to be ignored by the format param).
Or another way to look at this, is there a way to name or annotate the properties of a GET request DTO so that ServiceStack will populate those properties with the values of request headers during deserialization? This could provide an alternative approach for solving this problem.

how do i resend a request after processing it inside my apigee endpoint

I have a endpoint called get user data which accepts a token
I need to read this token in my apigee and send it to tokenVarificationExtUrl
which gets back to me with
a) valid 200
b) userid attached with that token
now what i have to do is i need to read the response header and then conditionally check it for 200 success and then extract the userid from the response.
Once its extracted i need to attach it with another request; which i need to send to getUserData external url
which will get back to me with required user details.
I am successful of extracting data and doing conditional check. I am seeking help for
how do i send another request to getUserData external url.
You need to use a few policies in your proxy.
For example
For checking a header and throwing an error, you may want to use rasie fault policy conditionally
For making an API call to external end-point you can use service callout policy or a standard target
For exrtacting response data from json or xml payload you can use json path of xpath policies
and so on.
I suppose you may want to take a look at a few sample proxies with these functions to be able to design your own.
Check this link out. http://apigee.com/docs/content/using-sample-api-proxies

Is there a default http request header to identify the user making a request?

In the data model behind my RESTful API there are several entities with the CreatedBy/ModifiedBy fields. The only access to this data is through my API, and as such, the fields should be populated with the user id of the user making the request to my API.
I have considered either adding these fields to the models exposed by my API or expecting a request header containing the user id on all PUT/POST/DELETE requests. I would be interested in any opinions as to which approach is best, or any other approach.
I like the idea of providing it in the header since it is necessary for every request and I am wondering if there is a standard request header to contain the information, or a common x-header.
I have seen the from request header; however, it seems to be defined as the email address of the user making the request and I need to pass the user id.
In our current implementation, we use the authorization header to authenticate the calling application with the API, and not for a specific user.
Which header would you use to pass information to identify the user making a request?
You can extend the Authorization header to add your own parameters. Both the Digest and OAuth authorization schemes support parameters. The Basic scheme already have the user credentials readable. Something like:
Authorization: OAuth realm="Photos",
oauth_consumer_key="dpf43f3p2l4k3l03",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="137131200",
oauth_nonce="wIjqoS",
oauth_callback="http%3A%2F%2Fprinter.example.com%2Fready",
oauth_signature="74KNZJeDHnMBp0EMJ9ZHt%2FXKycU%3D",
xoauth_user_guid="alganet"
Yahoo! does something similar with their OAuth implementation, but in another context.
http://developer.yahoo.com/oauth/guide/oauth-accesstoken.html.
However, if these fields are shown or exposed somehow in your public API, they belong to RESTful resources and should be represented always in the body, not the headers. If you GET the username in the message body, you should POST the username using the message body as well.
Assuming you can use HttpClient
HttpClient client = HttpClientManager.getNewClient();
HttpMethod get = new GetMethod(...);
get.addRequestHeader("x-newHeader", "value");
more here
OR using URLConnection using setRequestParameter

Resources