简体   繁体   English

asp.net向api发送获取请求并获取json结果

[英]asp.net send get request to api and get json result

How can I send 'get' request from the server to API and get result with json data? 如何从服务器向API发送“获取”请求并获取json数据的结果? I heard about HTTPClient in .net 4.5 maybe there is something like that in .net 4.0? 我听说过.net 4.5中的HTTPClient,也许在.net 4.0中有类似的东西?

For older Framework version You can use either WebClient which is really simple class for downloading/uploading data, or use HttpWebRequest . 对于较旧的Framework版本,您可以使用WebClient(它是用于下载/上传数据的非常简单的类),也可以使用HttpWebRequest WebRequest is lower level, but You can define method(GET,POST), UserAgent etc. Here You can find example about using WebRequest to do POST. WebRequest是较低级别的,但是您可以定义方法(GET,POST),UserAgent等。 在这里,您可以找到有关使用WebRequest进行POST的示例。

If You just want to get returned JSON from adress, WebClient should be sufficent. 如果您只是想从地址中返回JSON,则WebClient应该足够。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM