Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将参数传递给httpget和httppost_C#_Asp.net Mvc_Controller_Http Get - Fatal编程技术网

C# 将参数传递给httpget和httppost

C# 将参数传递给httpget和httppost,c#,asp.net-mvc,controller,http-get,C#,Asp.net Mvc,Controller,Http Get,我正在制作一个简单的Whois检查程序,以获取域名的Whois结果并将其显示在网站上 我正在使用MVC,我已经创建了checker类和视图,但是我不知道如何在我的控制器中准确配置httpget和httppost操作 这是whois类: using DATname.Models; using System; using System.Net; using System.Net.Sockets; using System.Text; public class ZapytanieWhois {

我正在制作一个简单的Whois检查程序,以获取域名的Whois结果并将其显示在网站上

我正在使用MVC,我已经创建了checker类和视图,但是我不知道如何在我的控制器中准确配置httpget和httppost操作

这是whois类:

using DATname.Models;
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class ZapytanieWhois
{
    public string NazwaDomeny { get; set; }

    public string RodzajTLD { get; set; }

    public string SerwerWhois { get; set; }

    public string Odpowiedz { get; set; }

    public void SprawdzanieTLD(string Domena)
    {
        Domena = NazwaDomeny;

        if (Domena.Contains("http://"))
        {
            Domena = Domena.Replace("http://", "");
        }

        if (Domena.Contains("www."))
        {
            Domena = Domena.Substring(4);
        }

        else
        {
            if (Domena.IndexOf('.') != -1)
            {
                int kropka = Domena.IndexOf('.');
                string TLDzKropka = Domena.Substring(kropka);
                string TLD = TLDzKropka.Replace(".", "");
                RodzajTLD = TLD;
                this.SerwerWhois = this.UstalanieSerweraNaPodstawieTLD(TLD);

                // Connect to the whois server
                TcpClient tcpClient = new TcpClient();
                tcpClient.Connect(this.SerwerWhois, 43);
                NetworkStream networkStream = tcpClient.GetStream();

                // Send the domain name to the whois server
                byte[] buffer = ASCIIEncoding.ASCII.GetBytes(Domena + "\r\n");
                networkStream.Write(buffer, 0, buffer.Length);

                // Read back the results
                buffer = new byte[8192];
                int i = networkStream.Read(buffer, 0, buffer.Length);
                while (i > 0)
                {
                    i = networkStream.Read(buffer, 0, buffer.Length);
                    Odpowiedz += ASCIIEncoding.ASCII.GetString(buffer); ;
                }
                networkStream.Close();
                tcpClient.Close();
            }
            else
            {
                Odpowiedz = "Prosze wpisać poprawną domenę.";
            }
        }
    }


    private string UstalanieSerweraNaPodstawieTLD(string TLD)
    {
        DatnameContext db = new DatnameContext();

        string serwer = db.TLDs.Find(TLD).Whois_Server;

        return serwer;
    }
}
我的看法是:

@model ZapytanieWhois

@{
ViewBag.Title = "Dane szczegółowe";
}

@section featured {
<section class="featured">
    <div class="content-wrapper">
        <hgroup class="title">
            <h2>WHOIS.</h2>
        </hgroup>
    </div>
</section>
}

@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<form>
Wpisz nazwę domeny : <input type="text" height="10" width="30" name="Domena" id="Domena"/>   |   <input type="submit" value="Sprawdź Who-Is" />
</form>

<div class="display-label">
    <strong>Odpowiedź serwera: </strong>
    @Html.DisplayFor(model=> model.Odpowiedz)
</div>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

欢迎任何帮助,因为我是MVC和C#的新手。

您的
输入
名称(
name=“Domena”
)和控制器参数(
CheckWhoIs(string Domena)
)必须匹配ModelBinder才能工作,即

<input type="text" height="10" width="30" name="domena"/>


另外,从设计的角度来看,如果要将
ZapytanieWhois
类用作
ViewModel
,那么您可能在
ZapytanieWhois
类中做得太多了。相反,在我看来,只保留
ViewModel
的简单属性,然后在控制器或控制器使用的助手方法中执行网络IO的繁重工作。

您的
表单
既没有
动作
也没有
方法
属性。我猜应该是这样。@ArtyomNeustroev说得好-默认操作返回到当前url-@ArtyomNeustroev-谢谢。在这种情况下,我可以删除标记并将其留给Html.BeginForm来处理数据,我猜?
<input type="text" height="10" width="30" name="domena"/>