通过VB net 2017消费REST服务 [英] Consume a REST service via VB net 2017

查看:76
本文介绍了通过VB net 2017消费REST服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家下午好。我必须开发一个VB Net程序来使用REST Web服务,我之前从未这样做过,所以我有点紧张。



有事实。



- 我计划使用HttpWebRequest类。我还想过使用WebClient类,但我找到了已经开发的代码,所以我决定使用它。



- 我必须取消电子发票盖章,所以我也必须在我们的ERP系统中进行必要的更新,但是现在,我只想看到网络消费功能。



- 我必须下载取消确认的XML文件(西班牙语:AcusedeCanceclaón)和PDF文件,并将它们存储在我们的网络中。



有人认为它最好是使用WebClient类还是其他类?



任何人都可以给我一个关于在哪里查找最具体代码示例的提示或建议吗?或任何消化,或在哪里寻找快速介绍?



提前感谢任何帮助,研究员。



我的尝试:



我一直在学习和搜索关于REST的互联网服务以及如何使用它们,答案和足够的提示才能开始编码,现在我必须继续开发。



我还决定使用HTTPWebRequest类基于我所看到的以及我们安装的条件。

Good afternoon everybody; I have to develop a VB Net program to consume a REST Web service, and I´ve never done this before, so I´m a little nervous.

There are the facts.

- I plan to use the HttpWebRequest class. I also thought of using the WebClient class, but I located already developed code of the late so I decided to use it.

- I have to cancel an electronic invoice already stamped, so I also have to make the necessary updates in our ERP system, but for now, I just want to see the web Consuming functions.

- I have to download the XML File of the cancellation acknowledgment (in spanish: "Acuse de Cancelación") and the PDF file also, and store them in our network.

Somebody thinks it would be better to use the WebClient class, or another ?

Can anybody give me a hint or advice about where to look for the most specific possible example of code ?, or any sugestion, or where to look for a quick introduction ?

Thanks in advance for any help, fellows.

What I have tried:

I´ve been studying and searching thru the Internet about REST services and how to consume them, answers and enough hints to be able to start coding, now I have to proceed to development.

I also decided to use the HTTPWebRequest class based and what I saw and the the conditions of our installation.

推荐答案

所以你想要完成的事情是非常直接但我猜你会因为你而感到紧张正在整个项目中查看项目,而不是将您想要完成的项目分解为更小的部分。



假设当您说需要下载XML文件而您不是谈论API返回XML作为其响应,无论您是下载XML文件还是PDF文件......您正在做的事情的根源仍然是下载文件。



然后,第一步是弄清楚如何下载文件。无论你使用HttpWebRequest类,WebClient还是HttpClient ......都没关系。他们都会做你需要做的事情,所以只要选择你认为最好的东西,并让你以最好/最简单的方式完成你的最终目标。



一些链接下载文件



从URL代码VB.NET下载文件 - 堆栈溢出 [ ^ ]



WebClient.DownloadFile方法(字符串,字符串)(System.Net) [ ^ ]



如何:在Visual Basic中下载文件Microsoft Docs [ ^ ]



如何在VB中下载文件 - Google搜索 [ ^ ]



你的第二个问题吧看起来你需要调用ERP系统公开的API。这很简单,你需要做的就是谷歌在VB中发布到网络服务。



使用ASP.net和VB.net设置POST REST Web服务 - dotnetco.de [ ^ ]



我可以在vb.net中对网络服务进行POST吗? [ ^ ]



然后将它们组合在一起,只需使用代码下载文件以及您编写的任何代码来处理XML或PDF文件,并且包括回拨到您的ERP系统的呼叫,只要我取消正确地理解了你,你已经完成了你需要做的事情。



至于HttpWebRequest和WebClient之间的区别...... google上有很多东西区别在于WebClient只是一个建立在HttpWebRequest之上的抽象。如果你不想在请求的作用方面担心那么多的管道,请使用WebClient ......否则使用任何一个类进行API调用都没有错。
So what you are trying to accomplish is pretty straight forward but Im guessing you are getting nervous because you are viewing the project as a whole instead of breaking down what you want to accomplish into smaller pieces.

Assuming when you say you need to download an XML File and you aren't talking about the API returning XML as its response, whether you are downloading an XML file or a PDF file...the root of what you are doing is still downloading a file.

First step then is to figure out how to download a file. Whether you use HttpWebRequest class, WebClient or HttpClient...it doesn't matter. They will all do what you need to do so just pick whatever you feel is best and allows you to accomplish your end goal the best/easiset way possible.

Some links to downloading a file

Download File From URL Code VB.NET - Stack Overflow[^]

WebClient.DownloadFile Method (String, String) (System.Net)[^]

How to: Download a File in Visual Basic | Microsoft Docs[^]

how to download a file in VB - Google Search[^]

Your second problem it looks like is you need to call an API exposed by your ERP system. Thats pretty simple, all you need to do is google "post to web service in VB".

Setup POST REST Webservice with ASP.net and VB.net - dotnetco.de[^]

Can I do a POST in vb.net to a web service?[^]

Then bringing it together, just use the code to download the file along with whatever code your write to process the XML or PDF files, and include the call back to your ERP system and as long as I understood you correctly, you've accomplished what you needed to do.

As for the difference between HttpWebRequest and WebClient...there is plenty of stuff on google as to what the difference is but essentially WebClient is just an abstraction built on top of HttpWebRequest. If you don't want to worry about as much plumbing necessarily in terms of what the request is doing, use WebClient...otherwise there is nothing wrong with utilizing either class for API calls.


这篇关于通过VB net 2017消费REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆