New line in Meteor HTTP POST - http

What is the correct way to insert a new line in a Meteor.http POST call?
Here's what I usually do:
var result = HTTP.call("POST", URL, {
params: {
field: value
},
headers:{
"[HEADER FIELD]":"[HEADER VALUE]"
}
});
I want the value in this case to be multiple strings separated by new lines. I have tried:
value = "firstItem" + "%0A" + secondItem + "%0A" + thirdItem
The API I am using expects value to be different items, each on a new line. When I post this request, the API consumes this as a string and doesn't identify the items as separate inputs. Any thoughts?

A POST request usually has it's parameters separated by & if you're using application/x-www-form-urlencoded:
parameter=value&also=another
That being said, if you use application/x-www-form-urlencoded, the W3C spec states that "%0D%0A" is a new line so you can try that too.
https://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1

Related

How to generate query string in golang?

In my use-case, I need to post data to url, however the data itself is a query string.
Example:
curl -POST -d "username=abc&rememberme=on&authtype=intenal" "https..somemdpoint"
What I have is a method which takes in 3 values
function makePostRequest(username string, rememberme string, authtype string, endpoint string) {
// post a curl request.
}
I am struggling to find any library that would return me a query string if I provided it with parameters.
I tried doing this:
q := req.URL.Query()
q.Add("api_key", "key_from_environment_or_flag")
q.Add("another_thing", "foobar")
fmt.Print(q)
But realized it actually returns Values which is a map so its no good.
Is there any method in golang that creates a queryString ?
You almost got it. Call Values.Encode() to encode the map in URL-encoded form.
fmt.Print(q.Encode()) // another_thing=foobar&api_key=key_from_environment_or_flag
Create the map directly instead of using req.URL.Query() to return an empty map:
values := url.Values{}
values.Add("api_key", "key_from_environment_or_flag")
values.Add("another_thing", "foobar")
query := values.Encode()
Use strings.NewReader(query) to get an io.Reader for the POST request body.

How to traverse object with dynamic keys in Paw?

Let's say we have the following JSON response:
{
"abcd1234": {
"foo": "bar"
}
}
How would "bar" be accessed in a response parsed body value? In the response, "abcd1234" could be anything. But we want the first key in the object (in JavaScript this would be Object.keys(res)[0]).
Paw makes it easy to parse JSON (and XML) responses and access subfields via their key-path.
This documentation article may help: https://paw.cloud/docs/advanced/reuse-values-from-previous-responses
Insert the Response Parsed Body dynamic value
Set the input request and extract the needed value
In your example, the key path will be:
abcd1234.foo
Though, it seems like you need to access the path without knowing the key before hand. If so, one way would be to use a JavaScript snippet to be able to achieve the behavior you want.
On any field, you may right-click and pick Extensions > JS Script.
Here's a snippet that may fit your needs:
function evaluate(context){
var request = context.getCurrentRequest();
var exchange = request.getLastExchange();
var body = JSON.parse(exchange.responseBody);
var key = Object.keys(body)[0];
var value = body[key].foo;
return value;
};

POST data empty ( or not exist ) when I receive post back from TPV provider

I'm trying to implement a service Redsys payments on my .net website.
The payment is successful (data are sent by post) but when the POST data back to my website ( to confirm the payment ) and i try to retrieve them with:
Request.form string value = [ "name"]
the value is always empty
I tried to count how many are in Request.Form.Keys.Count and always gives me zero values.
In the vendor documentation it indicated that the variables may be collected with Request.form [ "name"] and I called them to ask why I do not get the data and they dont know why...so I'm desperate,
What may be due?
I have reviewed the header I get from the server ( width Request.Headers ) and have the following parameters. HttpMethod:: GET Requestype: GET and contentlength: 0 . My bank tell me that they response POST not GET... so it´s a mistery. May be the error is becouse that sendings are made from a https to a htttp ?
You are receiving a POST without parameters.
The parameters are in the content of the call.
You should read the content and get the values of each parameter:
[System.Web.Http.HttpPost]
public async Task<IHttpActionResult> PostNotification()
{
string body = "";
await
Request.Content.ReadAsStreamAsync().ContinueWith(x =>
{
var result = "";
using (var sr = new StreamReader(x.Result))
{
result = sr.ReadToEnd();
}
body += result;
});
In body you can read the parameters (the order of them can change).

asp.net mvc outputting json with backslashes ( escape) despite many attemps to filter

i have an asp.net controller that output Json as the results
a section of it is here
returnString += string.Format(#"{{""filename"":""{0}"",""line"":[", file.Filename);
what i get returned is this:
"{\"DPI\":\"66.8213457076566\",\"width\":\"563.341067\",\"editable\":\"True\",\"pricecat\":\"6\",\"numpages\":\"2\",\"height\":\"400\",\"page\":[{\"filename\":\"999_9_1.jpg\",\"line\":[]},{\"filename\":\"999_9_2.jpg\",\"line\":[]}]]"
i have tried to return with the following methods:
return Json(returnString);
return Json(returnString.Replace("\\","");
return Json will serialize my string to a jSon string, this i know but it likes to escape
for some reason, how can i get rid of it ????
for info this is how i call it with jQuery:
$.ajax({
url:"/Products/LoadArtworkToJSon",
type:"POST",
dataType: "json",
async: false,
data:{prodid: prodid },
success: function(data){
sessvars.myData = data;
measurements = sessvars.myData;
$("#loading").remove();
//empty the canvas and create a new one with correct data, always start on page 0;
$("#movements").remove();
$("#canvas").append("<div id=\"movements\" style=\"width:" + measurements.width + "px; height:"
+ Math.round(measurements.height)
+ "px; display:block; border:1px solid black; background:url(/Content/products/"
+ measurements.page[0].filename + ") no-repeat;\"></div>");
your help is much appreciated
thanks
Are you looking at it in the debugger in VS or in the browser? The debugger will include the extra slashes when it displays it, while the actual output will not consist of those values.
Edit: Try passing an object to Json instead of a custom string. Your string is already in Json format (ish), so passing it to Json is re-ecoding it.
return Json(new { filename = "yourfilename" } );
or
return "yourfilename";
...etc, adding in whatever properties you need.

In MVC app using JQGrid - how to set user data in the controller action

How do you set the userdata in the controller action. The way I'm doing it is breaking my grid. I'm trying a simple test with no luck. Here's my code which does not work. Thanks.
var dataJson = new
{
total =
page = 1,
records = 10000,
userdata = "{test1:thefield}",
rows = (from e in equipment
select new
{
id = e.equip_id,
cell = new string[] {
e.type_desc,
e.make_descr,
e.model_descr,
e.equip_year,
e.work_loc,
e.insp_due_dt,
e.registered_by,
e.managed_by
}
}).ToArray()
};
return Json(dataJson);
I don't think you have to convert it to an Array. I've used jqGrid and i just let the Json function serialize the object. I'm not certain that would cause a problem, but it's unnecessary at the very least.
Also, your user data would evaluate to a string (because you are sending it as a string). Try sending it as an anonymous object. ie:
userdata = new { test1 = "thefield" },
You need a value for total and a comma between that and page. (I'm guessing that's a typo. I don't think that would compile as is.)
EDIT:
Also, i would recommend adding the option "jsonReader: { repeatitems: false }" to your javascript. This will allow you to send your collection in the "rows" field without converting it to the "{id: ID, cell: [ data_row_as_array ] }" syntax. You can set the property "key = true" in your colModel to indicate which field is the ID. It makes it a lot simpler to pass data to the grid.

Resources