How to pass form parameters to a third-party web form with Zoho-Creator-Deluge's InvokeUrl() function?
Here is the code I have tried:
Try-1
auth_url = "https://example-form.com"
header_data = Map();
header_data.put("Content-Type","multipart/form-data");
payload = Map();
payload.put("username",app.App_Username);
payload.put("password",app.App_Password);
response = invokeurl
[
url :auth_url
type :POST
parameters:payload
headers:header_data
detailed: true
];
// debug
info response;
Try-2
auth_url = "https://example-form.com"
header_data = Map();
header_data.put("Content-Type","multipart/form-data");
payload = List();
username = {"paramName":"username","content":app.App_Username,"stringPart":"true"};
password = {"paramName":"password","content":app.App_Password,"stringPart":"true"};
payload.add(username);
payload.add(password);
response = invokeurl
[
url :auth_url
type :POST
files :payload
headers:header_data
detailed: true
];
// debug
info response;
Both Try-1 and Try-2 result in the form-page being returned in response instead of the expected logged-in page. There isn't an error message, so it seems to be ignoring the parameters in payload.
Is there a different syntax that works?
Thanks
Okay I found the issue was that I needed to use the Content-Type of x-www-form-urlencoded in my request headers. Here is the Try-1 updated with the working Content-Type:
header_data = Map();
//------------------------------------------------------------------
// This line is the fix!
//------------------------------------------------------------------
header_data.put("Content-Type","application/x-www-form-urlencoded");
payload = Map();
payload.put("username",app.App_Username);
payload.put("password",app.App_Password);
response = invokeurl
[
url :auth_url
type :POST
parameters:payload
headers:header_data
detailed: true
];
// debug
info response;
I want to create a new version for my project via redmine api rest.I folowed the doc on the web https://www.redmine.org/projects/redmine/wiki/Rest_Versions
url = Configuration.redmine+"/projects/#{project_id}/versions"
uri = URI.parse(url)
req = Net::HTTP::Post.new(uri.request_uri)
req.basic_auth(user, pass)
req["Content-Type"] = "application/json"
payload = {
version: {
name:version_name
}
}
req.body = payload.to_json
http = Net::HTTP.new(uri.host, uri.port)
return = response = http.request(req)
the actual result is a HTTPUnprocessableEntity (422) and i expected a 201 created. The response body looks like this:
<div id="content">
<h2>422</h2>
</div>
supposedly the redmine api, when it gives this type of error, in the response body comes the reason of the error but here it shows me nothing
I am trying to use the grafana api (doc here http://docs.grafana.org/http_api/alerting/) to get the list of all the alerts in grafana.
Here's what I tried:
uri = URI("http://example:3000")
headers = {
'Authorization'=>'Bearer test',
'Content-Type' =>'application/json',
'Accept'=>'application/json'
}
http = Net::HTTP.new(uri.host, uri.port)
request1 = Net::HTTP::Get.new("/api/dashboards/uid/uKH1CKVmk")
response1 = JSON.parse(http.request(request1).body)
This one works, it returns the json of the dashboard, but when I try :
request2 = Net::HTTP::Get.new("/api/alerts?state=ALL") or
request2 = Net::HTTP::Get.new("/api/alerts?dashboardId="+response1["id"].to_s+"")
request2['Authorization'] = "Bearer test"
request2['Content-Type'] = "application/json"
request2['Accept'] = "application/json"
I get an empty json.
Any ideas what I am doing wrong ?
Thanks,
Nicu
Found the problem, when I created the API token I selected "Viewer" permissions, I was thinking its enough to just make a get request on alerts, but apparently it is not, made a new API token with "Admin" permissions and it works.
I have a jmeter login script where user logs in and logs out. The detailed screenshots are attached below.
Request data is as attached:
In the response date , the authorization token is generated:
And the regular expression for the same is as below:
I am passing the value as parameter in 55/users:
When I'm running the script it is failing:
Here is the response data:
Use Header Manager to pass the Token as a Header so you would have:
See for more details:
https://stackoverflow.com/a/43283700/460802
If you're looking to learn jmeter correctly, this book will help you.
A bit easier JMeter setup (login/get):
Thread Group
HTTP Request, Body Data: { "Login":"some", "Password":"credentials" }
HTTP Header Manager: content-type application/json
JSON Extractor - Names of created variables: Token; JSON Path expression: tokenName (root level in my case)
HTTP Request
HTTP Header Manager: content-type -> application/json; Authorization -> Bearer ${Token}
Response Assertion: Fields to Test = Response Code; Pattern Matching Rules = Equals, Not; Pattern to Test 401
View Results Tree to check results
Local IE Ajax version in case...
<SCRIPT>
var baseUri = 'https://localhost:port';
var tokenUri = '/something';
var getUri = '/restrictedData';
var token;
var form = { "Login":"some", "Password":"credentials" };
postRequest(baseUri + tokenUri, form, gotToken)
function gotToken(progress) {
var response = progress.srcElement;
if (response.status != 200) {
document.body.innerText = "Error:\n" + response.response;
return;
}
token = JSON.parse(response.response);
console.log(JSON.stringify(token));
var restricted = getRequest(baseUri + getUri, token.tokenName, gotRestricted);
}
function gotRestricted(progress) {
var jsonStr = progress.srcElement.response;
var jsonObj = JSON.parse(jsonStr);
document.body.innerText = JSON.stringify(token,null,2) + '\n\n' + JSON.stringify(jsonObj,null,2);
}
function getRequest(url, token, callback) {
var xhr = new XMLHttpRequest();
xhr.onloadend = callback;
xhr.open('GET', url);
xhr.setRequestHeader('contentType', 'application/json')
if (token) xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send();
return xhr;
}
function postRequest(url, body, callback) {
var xhr = new XMLHttpRequest();
xhr.onloadend = callback;
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify(body));
return xhr;
}
</SCRIPT>
Add Bearer ${token} in HTTP Header Manager available under failing HTTP Request.
If you already have the bearer token and just want to use in in header manager then,
in HTTP HEADER MANAGER tab, put these values under NAME and VALUE column respectively.
Name: Authorization
Value: Bearer "add your actual token without quotes"
Once you've extracted the token from the token API request, use this token in the HTTP Authorization Header manager for subsequent API's. Example below:
Header Name: Header Value Authorization: Bearer ${generated_token}
Where "generated_token" is a variable containing the extracted token.
I got cUrl from my API and then I imported it.
use Authorization as parameter name and value should be
Bearer ${variable_name}
I'm using Net::HTTP to make a POST request:
uri = 'service.example.com'
https = Net::HTTP.new(uri)
https.use_ssl = true
path = "/service_action"
data = request_body_obj.to_json
response = https.post(path, data, {'Content-Type' => 'application/json'})
My request is timing out for some reason. To debug why, I'd like to see the text of the request body and headers of my request. Is there a way to do that?