我如何在MVC中向/从网站发送/获​​取请求/响应

时间:2022-11-30 08:59:57

im new in mvc. What im thinking about: the project is about to send phonenumbers to website and get informations about this number. I want to send many phonenumbers to a website (or many) ,and get informations about these numbers.And show the results in the View. im so confused about: should i make the "requset and response" in the "Controller" and send the resultes to the view to show?.Or should i send my numbers to the "View" and do all the process there?. Any help with codes?

我是mvc的新人。我在想什么:该项目即将向网站发送phonenumbers并获取有关此数字的信息。我想向网站(或许多)发送许多电话号码,并获取有关这些号码的信息。并在视图中显示结果。我很困惑:我应该在“控制器”中进行“重新设置和响应”并将结果发送到视图以显示?。或者我应该将我的号码发送到“视图”并在那里完成所有过程吗?任何代码帮助?

1 个解决方案

#1


You don't do business logic in views.

您不在视图中执行业务逻辑。

Depending on how "layered" you want your code to be, you perform the HTTP requests to external websites either in your controller, or in a separate class that you call from your controller.

根据您希望代码的“分层”程度,您可以在控制器中或从控制器调用的单独类中对外部网站执行HTTP请求。

How to do so is explained in many Q&As, like HttpClient vs HttpWebRequest, .NET HttpClient. How to POST string value?, What difference is there between WebClient and HTTPWebRequest classes in .NET?, and so on.

在HttpClient与HttpWebRequest,.NET HttpClient等许多问答中都解释了如何做到这一点。如何POST字符串值?,.NET中的WebClient和HTTPWebRequest类之间有什么区别?等等。

#1


You don't do business logic in views.

您不在视图中执行业务逻辑。

Depending on how "layered" you want your code to be, you perform the HTTP requests to external websites either in your controller, or in a separate class that you call from your controller.

根据您希望代码的“分层”程度,您可以在控制器中或从控制器调用的单独类中对外部网站执行HTTP请求。

How to do so is explained in many Q&As, like HttpClient vs HttpWebRequest, .NET HttpClient. How to POST string value?, What difference is there between WebClient and HTTPWebRequest classes in .NET?, and so on.

在HttpClient与HttpWebRequest,.NET HttpClient等许多问答中都解释了如何做到这一点。如何POST字符串值?,.NET中的WebClient和HTTPWebRequest类之间有什么区别?等等。