Replicating POST data taken from Fiddler in new POST - json

I am trying to replicate a post I have captured in Fiddler, I have one variable that is in what looks like JSON and I dont know how to replicate this in a POST string.
I have (from Fiddler):
{"var1":"string1", "params":{"1":"string2", "2":50, "3":50, "4":"string3"}, "var2":"string4"}
So my question is how do I represent the "params" variable in a POST url?
Currently I have ...[URL]?var1=string1&(PARAM STUFF)&var2=string4. What do I put in the PARAM STUFF place?
Thanks!

Related

How to process Vue/Axios Json payload posted data on Yii2

It took me a while to understand this, being that it was a little obvious. I will answer myself, so other can benefit of the answer and ofcourse to see if there's a better way to do this. The problem was based on Axios/Yii2 but I guess this will apply equally to other frontend libraries/frameworks sending data to Yii2.
I needed to post data from a small form made on Vuejs, sending the request Axios to a Action/Controller on Yii2, so data is sent on a simple POST request and the post is getting to the controller, but I was not able to receive the data on the action, $_POST | $post arrives empty (checked using xdebug).
As much as I remember, this had something to do with security. But I already tried by disabling public $enableCsrfValidation, so that was not the problem.
public $enableCsrfValidation = false;
But no matter what, data was not being added to the request/post data inside Yii2.
The following Image, explains the problem you will find there:
The Axisos method that sends the post with test data.
The Yii2 Action stpoed at the place, I should be able to see data.
The capture of the xdebug variables and data for the request.
The capture of Chrome where you can check the payload is sent.
The answer is as I said "kind of obvious", but I could not see that, and I am sure some other devs will probably fall on this.
After searching like crazy and asking everyone, I tried sending the request by using Postman app, yup the best thing I know to test apis.
Dont forgue to add the xdebug cookie to be able to debug your PHP Endpoint.
There I found the first clue «the obvious part», I was not sending data as a form-data, Axios and other libraries, send the data as a raw (application/json) payload.
This means that Yii2 will no be able to find the data inside the post request, yes its there but Yii2 magic will not work, neither you will find this data inside $GLOBALS or in $_POST.
So reading the Yii2 documentation I found that inside request I can use a function that will help me recovering the Raw data, so to do this use the following line:
$raw_data = Yii::$app->request->getRawBody();
Now, that data gets to you as a simple, raw json string, so use the power of PHP to parse it to an object.
$object= json_decode($raw_data );
And finally use the data inside by calling the properties you look for, sent on the pay load:
Json Payload:
{
"msg":"This is my payload",
"id":"11"
}
To use it:
echo $object->{'msg'}; // prints: This is my payload
So that's the way to handle that, now I would like some other points of view to see if there's a better way or cleaner way to do this. Hope it helps.

API - cURL with GET and POST in same request

Sorry if this has been answered but I've been googling for a while and can't seem to find anything. I'm wondering how to send a GET & POST in the same cURL payload if that's possible? In other words, send a GET request from one website's API (in my case returns json data) and then have this post to another application all in the same request. Basically I'm trying to do the same sort of thing that IFTTT does, for ex. when API-a posts news story, then post news story to API-b.
Basically, I can currently send a payload of the text for the url that I'm trying to get to a webhook, but what I'd like to do is have the payload GET the info from a URL then POST this to another url. Is this possible in the same payload?
No, it is not possible with HTTP.
You need to first get the results of the first transfer and then send that to the next one, but you can indeed do that in a single command line if you'd like. Something like this:
curl http://1.example.com/get.html | curl -d#- http://2.example.com/post.php

Pentaho HTTP Post using JSON

I'm brand new to Pentaho and I'm trying to do the following workflow:
read a bunch of lines out of a DB
do some transformations
POST them to a REST web service in JSON
I've got the first two figured out using an input step and the Json Output step.
However I have two problems doing the final step:
1) I can't get the JSON formatted how I want. It insists on doing {""=[{...}]} when I just want {...}. This isn't a big deal - I can work around this since I have control over the web service and I could relax the input requirements a bit. (Note: this page http://wiki.pentaho.com/display/EAI/JSON+output gives an example for the output I want by setting no. rows in a block=1 and an empty JSON block name, but it doesn't work as advertised.)
2) This is the critical one. I can't get the data to POST as JSON. It posts as key=value, where the key is the name I specify in the HTTP Post field name (on the 'Fields' tab) and the value is the encoded JSON. I just want to post the JSON as the request body. I've tried googling on this but can't find anyone else doing it, leading me to believe that I'm just approaching this wrong. Any pointers in the right direction?
Edit: I'm comfortable scripting (in Javascript or another language) but when I tried to use XmlHttpRequest in a custom javascript snippet I got an error that XmlHttpRequest is not defined.
Thanks!
This was trivial...just needed to use the REST Client (http://wiki.pentaho.com/display/EAI/Rest+Client) instead of the HTTP Post task. Somehow all my googling didn't discover that, so I'll leave this answer here in case someone else has the same problem as me.
You need to parse the JSON using a Modified JavaScript step. e.g. if the Output Value from the JSON Output is called result and its contents are {"data"=[{...}]}, you should call var plainJSON = JSON.stringify(JSON.parse(result).data[0]) to get the JSON.
In the HTTP Post step, the Request entity field should be plainJSON. Also, don't forget to add a header for Content-Type as application/json (you might have to add that as a constant)

Is is possible to Post a file and json body with RestSharp?

I'd like to post one file and a json object to my server. Posting as a Parameter works fine, so this works:
request.AddFile ("MyPic", organisation.Pic, "Pic.png", "image/png");
request.AddParameter ("name", "test name");
But if my JSON object is something with a nested structure like:
{organisation:{
'name':'test',
'address':{
'line1':'foo',
'line2':'foo2'
}
}}
How do I post this, while maintaining the json structure.
If I set it in the content body i.e.:
request.AddBody (organisation);
the content is posted, but the file is not posted.
Is it possible to post both a json body and file?
So, I figured out a workaround, which suits my purposes. What I was looking for was to do a single post of both the file and associated meta-data. In this instance I serialised the object to a JSON string, set that as my parameter and de-serialised on the server. This works in my case but I accept that this may not be ideal for others. Thought it might help someone.
No.
When you use AddFile you are actually addding a body to your request. You can't send a request with 2 bodies.
Actually this will be possible very soon. There's a pull request on the RestSharp library that addresses this. I've started maintaining the project and will be merging it into master in the next day or so. Once there's enough stuff, I'll release a new NuGet package as well.

Can't see JSON response in JMeter View Results Tree

I was wondering if someone could tell me why I can't see the json response from a request that is also of type json in the JMeter View Results Tree. I know that the response is there because I use a regular expression to extract data (I wrote the reg ex based on result returned in Firebug). So the data can be extracted from the json response it just doesn't display in View Result Tree. I can see the json response for another request for a different app I performance test with JMeter, but that particular request is an ajax request. not sure
Add a sample writer and display content here.
http://jmeter.apache.org/usermanual/component_reference.html#Simple_Data_Writer
You will see the issue
HI there any one who looks in this post for jmeter, you may be bit worried when you cant find answers in internet regarding how to log your response when you sent a request , here is the solution and simple as it is...
just add a line like below.
result.setResponseData("put any content here to be displayed as String.", "UTF-8");
and check your response will be cool as you done.