Home > Net > The fetch how to application/x - WWW - form - urlencoded and webapi interaction?
The fetch how to application/x - WWW - form - urlencoded and webapi interaction?
Time:11-11
fetch (" http://localhost:58513/api/decheng/", { Method: "POST", Headers: { 'the content-type' : 'application/x - WWW - form - urlencoded', }, Body: {" LogId ": 3," UserName ":" test "}, })
The fetch by the above code, is unable to get to the value in the webapi, don't know what should be the right way?
USES 'the content-type:' application/json, passing json string is ok, I just want to know when 'the content-type:' application/x - WWW - form - urlencoded 'to webapi how to pass parameters and get the value
CodePudding user response:
The default is to form parameter passing. Webapi to parameters of the formdata If it is pass json, he shall take from the inputstream The url parameter, the querystring. Before and after the corresponding ok, no problem
CodePudding user response:
The default should be text/plain, if I take out the content-type, displays
This should be different and ajax,
Pass json string of words, can be the normal, just I want to know how to transfer formdata, and how to get to pass on the WEBAPI end formdata?
CodePudding user response:
Before I studied this issue. You may have a look before I write posts.
https://bbs.csdn.net/topics/392146314
This you can only restrain the clerk client.
If the client USES the way of your API method if using frombody formdata features of object is unable to receive value.
You can only
HttpContextBase context=(HttpContextBase) Request. The Properties (" MS_HttpContext "); HttpRequestBase request=context. The request; Var id=request. The Form (" id ");
This form.. Although you can get all the form. The transformed their.. But still more troublesome.
And this kind of form the key still can't repeat..
So you constraints at the front desk call postjson this way to go. Only. Now I have not very good solution.. Because he didn't want to write too much code..