拨打和接听在C#中的HTTP请求 [英] Making and receiving an HTTP request in C#
问题描述
我想让我的C#应用程序,以便能够发送HTTP请求和接收在运行时的答案
I want to make my C# application to be able to send an http request and receive the answer at runtime
这是我想从请求网站上的解释是这里
an explanation from the website I want to request from is HERE
我没有与任何经验之前,让我有点困惑的JSON,XML的东西 我知道我需要一个XML解析器或类似这样的东西来理解请求
I don't have any experience with that before, so I'm a little confused about the JSON, XML stuff I know I'll need an XML parser or something like this to understand the request
推荐答案
制作一个HTTP请求非常简单,如果你不希望对其进行自定义:一种方法调用<一个href="http://msdn.microsoft.com/en-us/library/fhd1f0sw.aspx"><$c$c>WebClient.DownloadString$c$c>.例如:
Making a HTTP request is very simple if you don't want to customize it: one method call to WebClient.DownloadString
. For example:
var client = new WebClient();
string html = client.DownloadString("http://www.google.com");
Console.WriteLine(html);
您将需要每次都构建正确的URL根据您链接到的文档。
You will need to build the correct URL each time as per the documentation you link to.
如果你用上面的例子中code谈谈你的API, HTML
(这实在是一般的响应数据)将包含XML或JSON作为一个字符串。这样,你会需要解析这个进入一些其他类型的对象树,让您可以与响应工作。
If you use the example code above to talk to your API, html
(which is really the response data in general) will contain either XML or JSON as a string. You would then need to parse this into some other type of object tree so that you can work with the response.
这篇关于拨打和接听在C#中的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!