【问题标题】:The type or namespace "HTTPGet" could not be found [duplicate]找不到类型或命名空间“HTTPGet”[重复]
【发布时间】:2018-02-09 10:23:32
【问题描述】:

我正在使用 Visual Studio 编写 C# 代码。 这是我有一些问题的代码部分:

HttpGet req = new HttpGet();
req.Request("http://checkip.dyndns.org");
string[] a = req.ResponseBody.Split(':');
string a2 = a[1].Substring(1);
string[] a3 = a2.Split('<');
string a4 = a3[0];
label3.Text = "Public IP Address: " + a4;

这就是我包含的内容:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Management;
using static System.Object;
using System.Net.Http;

我仍然得到这个错误:

找不到类型或命名空间“HTTPGet”。

我能做什么?

【问题讨论】:

  • @KobyDouek 命名空间“System.Web”中不存在类型或命名空间名称“Http”(您是否缺少程序集引用?)
  • 你从哪里得到的代码? CLR 中没有 HttpGet 类型。
  • HttpGet 不是一个类。 HttpGetAttribute 一个类,但它不用于发出请求。
  • 这段代码的意图完全是个谜。我找不到任何具有ResponseBody 属性的框架类型。你确定这不仅仅是某人的草图/伪代码吗?
  • 所以让我理解。你选择了一个你无法工作的答案。尽管原始答案中有 cmets,但您没有在该问题上选择另一个答案,而是寻求帮助,并且您在这里没有提及该答案?同时,原始问题有一个可接受的答案,这不是您选择的答案。这就是它的要点吗?

标签: c# winforms


【解决方案1】:

我认为您想通过 GET 创建 http 请求。你还需要类似于 HttpWebRequest 的东西:

C# how to properly make a http web GET request

或者你可能会混淆Understanding [HttpPost], [HttpGet] and Complex Actionmethod parameters in MVC的属性

【讨论】:

    猜你喜欢
    • 2011-06-13
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 2017-07-12
    • 2011-05-13
    相关资源
    最近更新 更多