How to Create Request in System.net.HttpWebRequest with x-www-form-urlencoded in vb.net - vb.net

I'am trying to create a web request on how to retrieve data with content type x-www-form-urlencoded but icannot find the example in internet. Can someone help me on how can i create a web request in System.net.HttpWebRequest with content-type that is from x-www-form-urlencoded and method is post.
This one is my working sample with the content-type is equal to form-data. But when i try this code with content-type x-www-form-urlencoded it is not working. What i need now is an htpp post request with content type x-www-form-urlencoded.enter image description here

Related

How to pull the token from Get request's response and input the same to Post request in JMeter for Rest API?

I am a beginner in JMeter, trying to perform load test to my Rest API. First, the Get request gets the access_token as below:
Then the following Post request runs with that authorization token to produce the Json, but I am missing something so the Post Request is failing as Authentication denied as below,
Added the Regular expression extractor to extract the token from the Get request's response as below:
Then storing it in the HTTP Header Manager in a variable as below
I am missing to link the value to the Post request, I dont know how to do it, please help.
In header manager, instead of access_token, the header name should be Authorization. Please reconfirm this with developer team / retry this same request in postman
The regex expression used should look something like this
"access_token":"(.*?)"
Also, another pro tip: because the response to getToken api call is JSON, you can use JSON Post Processor to extract the access_token by saying something like $.access_token. It is much clean way to process JSON object.

How do i get the csrf token from scenario 1 response using Karate framework?

I have application api url which has passed as Background with Basicauth. Using that i need to get an csrf token. I tried with responsecookies. Nothing is coming up.
Can you please let me know how to get the csrf token from that specific api. I am getting actual application response but not the cookies.
Please read the documentation and go through the demo examples. It depends on the response. There are 2 possibilities, cookie (or header) OR the response body itself (plain text or JSON / XML).
So it is up to you to extract it and then store it as a variable, and use it to build headers for all future responses.
Please refer to the demo example:
Given path 'signin', 'token'
When method get
Then status 200
And header X-CSRF-TOKEN = response
In this case, the token happened to be the entire response string.

How to call API with AntiForgeryToken using Postman in IdentityServer ASP.NET Core

I'm trying to test my API with Identity Server Asp.net Core using Postman.
This is the way that I'm trying to do:
First request HttpGet to https://localhost:5000/Account/Login and in response body I received: <input name="__RequestVerificationToken" type="hidden" value="CfDJ8MoS9upoM4dNp8Kx-AdvA-uYr13_PAkuMZpzYMV8UmxZq5GdLTvN-Ht5NpTLmPtlhL5d5z2Hu2vUJoJGhk1AMlARDcOwqgq7Cef1dfQL_vl4tIFM4kx9RZPz8DHU26-U9qLnKAIstZgR42-1FuGNh24" />
And in Cookie (not sure for what it is though):
Then HttpPost to https://localhost:5000/Account/Login with RequestVerificationToken with token received from body HttpGet request.
And always error 400 as you can see at screen shot above.
In Visual studio I can see that some request was catched but clearly was incorrect.
If I'll remove attribute [ValidateAntiForgeryToken] then of course everything works fine but obviously because that validation is disabled.
You'd need to do followings to send such a request:
1.) Enter __RequestVerificationToken key value (don't forget double underscores) into x-www-form-urlencoded
2.) You need to add .AspNetCore.Antiforgery cookie to the Cookies section in Postman.
For example like this
.AspNetCore.Antiforgery.1XHiLFgQI2w=your cookie value; Path=/; Domain=localhost;Expires=Session;
You can find .AspNetCore.Antiforgery cookie in Application section in Google Developer Tools
.AspNetCore.Antiforgery cookie in Google Developer Tools picture
Add cookie in Postman picture
Just spent a lot of time on this.
I did several things:
Setup an Environment and added a variable.
Added a pre-request script that...
Uses pm.SendRequest to Get the page
uses cheerio to find the first input field named __RequestVerificationToken and get its value
set the environmental variable to the value retrieved from the field
send the form data (since I'm using asp.net core, the values for the model), as x-www-form-urlencoded
and last, but not least, I added __RequestVerificationToken as one of the key value pairs in the form data and set it to the use the variable already setup
The main reason I am posting this answer is the last, I saw a lot of things on the web that indicated that name was supposed to be RequestVerificationToken, and that doesn't work, just leads to a 400 response (bad request).
In postman, you’d need to set the content type to form url encoded.
And send the request Verification token in the header as "RequestVerificationToken"
However, if you just need a Bearer token then you need to call
POST https://<your identity server>/connect/token with the

How do I create a mock server backend API with Postman?

I'm not understanding this tutorial.
I have a collection set up in Postman, I created a GET request in the collection and an example.
I'm not sure what to put in the request URL for the mock API example and what values to put in key/value in the request call.
Following the examples from the Postman documentation you mentioned - At Step 5 you should have a mock for the collection:
I've saved a simple GET request http://jsonplaceholder.typicode.com/users to the collection using the free jsonplaceholder API which will return details about users.
Once you have that response, hit the "Save Response" button and this will save that response as an example that can use with the mock server.
You can make requests against the mock server URL and add your route to the end of this in the Request Field. For me, it would look something like https://914aae16-28d5-47f1-8954-8a4d7b5e1daf.mock.pstmn.io/users

Can't Flattr an auto submit URL via the REST API

When flattring an auto submit URL via the REST V2 API with this request
POST https://api.flattr.com/rest/v2/flattr
{"url":"https://flattr.com/submit/auto?user_id=myuserid&url=myurl"}
I get this error, although the URL works fine in any browser and redirects to the existing thing.
{
"error_description" : "The requested thing(s) could not be found",
"error_uri" : "http:\/\/developers.flattr.net\/api",
"error" : "not_found"
}
So either I'm doing something wrong, or the error message is wrong, or something else?
You might have a problem with url encoding. For this to work you need to URL encode first the autosubmit URL.
http://blog.flattr.net/2011/10/api-v2-beta-out-whats-changed/ becomes http%3A%2F%2Fblog.flattr.net%2F2011%2F10%2Fapi-v2-beta-out-whats-changed%2F
Then you need to URL encode the whole autosubmit URL if you want to send it as a regular POST request.
http://flattr.com/submit/auto?url=http%3A%2F%2Fblog.flattr.net%2F2011%2F10%2Fapi-v2-beta-out-whats-changed%2F&user_id=flattr becomes http%3A%2F%2Fflattr.com%2Fsubmit%2Fauto%3Furl%3Dhttp%253A%252F%252Fblog.flattr.net%252F2011%252F10%252Fapi-v2-beta-out-whats-changed%252F%26user_id%3Dflattr.
If you are going to send it with JSON you don't need to URL encode the flattr autosubmit URL. Instead you do like the example below.
{"url":"http://flattr.com/submit/auto?url=http%3A%2F%2Fblog.flattr.net%2F2011%2F10%2Fapi-v2-beta-out-whats-changed%2F&user_id=flattr"}
This means that part of the URL will be URL encoded two times if you do a regular POST request and if you will send the data as JSON URL encode only one time. And when you do POST request with JSON body you need to set the Content-Type to application/json to make it work.
I forgot to set the Content-type header for the request. It needs to say "application/json".