I send a request from javascript to web api controller for example, ../api/person/updateBirthDate?id=1&birthDate=dd/MM/yyyy
I'm not sending json format so please don't say use Json serilizer. I just use post an url with parameters like form submit. How can I solve this issue at server side in order to get the date formatted as dd/MM/yyyy
First of all, the splash / is not allowed in the URL parameters. Use %2F instead. So the URL:
../api/person/updateBirthDate?id=1&birthDate=01/01/2000
should be sent as:
../api/person/updateBirthDate?id=1&birthDate=01%2F01%2F2000
Now, on your server, all the URL parameters will arrive as string, so you need to parse them like this:
int Id = Convert.ToInt32(Request.QueryString["id"]);
DateTime BirthDate = Convert.ToDateTime(Request.QueryString["birthDate"]);
Related
I want to test an API using Postman. I have 6 collections folder, in the 3 folders I call this API with the same request. If I use key-value pair, it will take times when there is a change in the request. So I put the request in collections variable as RAW JSON, but when I use this, the API returns Bad Request (400).
I'm using .NET 6 Web API, and my API look like this:
[HttpPost]
public async Task<IActionResult> Create([FromForm] TestViewModel vm)
{
// Process Data
}
For the notes, I use [FromForm] because I have file input in the form.
Is there any workaround for this?
Thanks in advance
if you want to post json to api it's better to user [FromBody] attribute, if you want to use [FromForm] you must use key-value form in form-data in postman.
for converting your model to json to store in collection use Newtonsoft.Json package.
follow below steps to send data as FromForm in Postman
Request Type: Post
In body select form-body or x-www-form-urlencoded send data as key value pairs. Class property as Key and value is your Requested Data
How can i get the 'id' when i want to match url like '/index?id=xxx' in koa-router? most articles on the web usually use url lick '/index/:id',but the back-end interfaces are not the case.
It does work the same on a back-end API, when you make a GET request to a web server it parses the query-string and uses the values to give you the intended response.
When handling a GET request using koa-router you can specify the query string, such as '/index/:id', and to consume the value in your code you would simply do
var id = ctx.request.query.id;
I need to send POST request through jmeter. I have checked the requests workflow through browser dev. tools. In my Post request I need to send form data and one string Query. Question is next - if i will add my string Query to URL will it work fine?
Example : somesite.com/something?refURL=someRef
If it is a POST request, usually any form data will be sent in the request body. Not like a query string in the GET request. But the format is same.
refURL=someRef add this in the parameters section.
Check here for more info.
https://www.w3.org/TR/html401/interact/forms.html#h-17.13
Why not? Query string and request body are different beasts and they are processed differently on server side.
Instead of asking this kind of questions, why don't you just record your test using JMeter's proxy server?
References:
URI Syntax - Query Component
HTTP Method Definitions - POST
Yes it will.
You can even use variables like:
/some/path?refURL=${someCalculatedRefUrl}
I am making an Ajax call to ASP.NET MVC endpoint. The url is something like this (Last parameter is null):
/employee/GetAllEmp/connID/Sale Dept/Month/Year/week/null?_dc=1371101563256
Server side:
public ActionResult GetAllEmp(string connID, string deptName, string month, string year, string week, string data)
When my application send request through IE, the endpoint at the server side is not called but when same request is being made through fire fox, system is able to call correct method.
What could be the reason? I googled around but could not find any answer :(
Please provide your suggestion.
Thank you
Based on what parameters your action method expects then /null will be parsed as a string literal rather than true null.
If this data is empty you should skip it completely and make your route accept an optional parameter
In the tutorial enter link description here they only show this:
var url = "http://api.twitter.com/1/statuses/public_timeline.json";
this.__store = new qx.data.store.Jsonp(url, null, "callback");
But I would need to communicate with my own server, so I've made some changes: (url and Jsonp to Json)
var url = "http://127.0.0.1:8000/";
this.__store = new qx.data.store.Json(url);
But I would need to be able to send some information to the server when the store make the request like:
{serviceToUseOnServer: 'articles', argument1: 'xxx'}
This is like a POST request, but I don't really know how to send that data to the server using qooxdoo's Store models. Please don't tell me to use GET and encode all that data in an url.
You got the possibility to configure the request object used to send the data. Just add a delegate to the store and implement the configureRequest method [1].
[1] http://demo.qooxdoo.org/current/apiviewer/#qx.data.store.IStoreDelegate~configureRequest