In VB.NET how can I call a URL using the POST method?
I am trying to utilize the API of a website but because I have no experience in web services, I don't know how to do this simple code.
If this question confuses you, or I need to add more information please ask!
You're looking for the HttpWebRequest class, or the newer and better HttpClient class.
Related
I have question about POST API.
I've made simple website. On the other side I have program which is sending some json data with POST method. Person who made this api want me to give them URL for this. I've never deal with api's so it's very difficult for me to find some starting point. Any one can help with some tutorial or advice? ;)
I'm trying to make a bot for Tumblr or Twitter, but both require OAuth requests. I'm not sure how to use a Net.WebRquest this way. I've searched all over and found very scarce information. I believe I am supposed to add some credentials in the header. This is what I have tried:
<pre>
Dim request As WebRequest = WebRequest.Create(URL)
request.Headers.Add(HttpRequestHeader.Authorization,
$"OAuth realm=""https://api.tumblr.com/"",
oauth_consumer_key=""{APIKEY}"",
oauth_token=""{TOKEN}"",
oauth_signature_method=""HMAC-SHA1"",
oauth_signature=""?"",
oauth_timestamp=""{(Now - New DateTime(1970, 1, 1)).TotalSeconds}"",
oauth_nonce=""{Now.GetHashCode()}"",
oauth_version=""1.0""")
<pre>
Assuming APIKEY and TOKEN are valid, I am still getting Error 401: Unauthorized. Also, what do I put in "oauth_signature"? That did not make any sense to me. This website contained the most useful information: https://oauth.net/core/1.0a/
Has anyone else here dealt with OAuth requests before, that can help me? If there were any examples out there, that would be wonderful. Thank you so much in advance.
~Nic
What jumps out at me immediately is that your parameters are not sorted alphabetically (which OAUTH requires).
Writing an OAUTH library from scratch is terrible terrible business and you should use an existing library unless you have a really good reason not to.
I am the author of TwitterVB, a .NET library for accessing the Twitter API. The code is hosted on GitHub and has a very permissive license. You'll find code can classes there that will make your implementation of OAUTH much easier.
Please note that I no longer maintain this library and there are a few things that have changed about the API that interfere with its functionality. The OAUTH pieces should all work as-is, however.
microsoft did not implement it, and will not do so according to this:
https://connect.microsoft.com/VisualStudio/feedback/details/770104/cannot-set-useragent-of-a-httpwebrequest-in-portable-class-and-winrt-libraries
But the web site I'm trying to get response from requires User-Agent header specified in the request, otherwise the response is wrong.
I am limited to using portable class library (PCL), since I'm working on mvvmcross cross platform project.
What is the best way to make such a web request?
As I was trying to point you to in my first comment, Dependency Injection is the best way to go about this. Here is a simple example from the MvvmCross documentation https://github.com/MvvmCross/MvvmCross/wiki/Service-Location-and-Inversion-of-Control#1-pcl-interface-with-platform-specific-implementation
Im trying to make a REST api work with VB.NET (http://help.cj.com/en/web_services/web_services.htm#Commission_Detail_Service.htm)
This is CJ commission's API.
The problem I have is that Im trying to add the service reference https://commission-detail.api.cj.com/v3/commissions but its not working, and when I go straight to that address on the web browser, its asking me for the developer key, which I have, but I dont know how to enter it.
Does anyone have a sample code on how to connect to that API?
Thanks!
I guess you don't need it by this time, but still, for those who'll have the similar question and get to this page: you should pass your developer key as the authorization header of your request. Depending on how you make requests, it could look something like this in VB.NET:
HttpWebRequest.Headers.Add("authorization", "your_dev_key")
Can anyone explain me the role of addRequestHeader method of ASIHTTPRequest class? Why do we need it?
P.S. Browsing over google and stackoverflow i see lots of people familiar with details of ASIHTTPrequest library. Where do you take the information?
Without any knowledge about that class, but most likely the method is used to send a custom header.
For example, when accessing a web service that is usually only hit through XHRs from JavaScript, it might require you to add a X-Requested-With: XMLHttpRequest header.
The info is from ASIHTTPRequest documentation
You need the method to specify header of request.
List of HTTP header fields