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..

CodePudding user response:

reference by_ love letter reply: 3/f
before I studied the problem. You can see I write posts before.

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..


Yes, I also like you, want to know is there any way in the case of using frombody, obtain the formdata value,

CodePudding user response:

Thank you! If there is no better way, that can limit the client only by value

CodePudding user response:

Backend overloading look line not line, can only like this

CodePudding user response:

Actually I first do this kind of idea is such.

Because the caller is generally not clear from where to copy the webclient. Then request.

Generally has two kinds of type a is formdata is a json I think as the server can resolve two different way. Instead of forcing client.

Size WeChat public interface is compatible with 2 kinds of model..

Later want to implement under the more troublesome.. I don't..

CodePudding user response:

Fetch 'application/x - WWW - form - urlencoded'
Use URLSearchParams
Fetch 'multipart/form - data'
With the FormData
Fetch 'application/json'
Using JSON. Stringify ({})
If you do not specify a content-type, Chrome will according to the body.

CodePudding user response:

refer to 7th floor by_ love reply:
actually I first do this kind of idea is such.

Because the caller is generally not clear from where to copy the webclient. Then request.

Generally has two kinds of type a is formdata is a json I think as the server can resolve two different way. Instead of forcing client.

Size WeChat public interface is compatible with 2 kinds of model..

Later want to implement under the more troublesome.. I don't.

No trouble, do receive parameters of a public class, class is translation, convert all kinds of parameters to dictionary types, the default receive with form, no data in the form with json receiving, simple, usually just these two line, or use the content-type judgment can also,
  • Related