Solved

VB.net REST API

Posted on 2011-03-22
7
1,409 Views
Last Modified: 2012-05-11
I want a simple piece of vb.net code which will carry out the following:
GET http://abc.def.com/ObjectTypeA/45
which includes authentication

TIA
0
Comment
Question by:jking1234
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35195222
1) What are you looking for?  

2) If you are trying to create a REST service, yave you already created the WCF REST service?  

3) Do you need to send that URL request (WebClient/HttpWebRequest)?
0
 

Author Comment

by:jking1234
ID: 35197905

I am trying to interact with a REST service that already exists.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35199891
You can use the System.Net.WebClient (simple wrapper for an HttpWebRequest), to submit a request, or if you have specialized requirements, than you move up to the HttpWebRequest.

HttpWebRequest example:

Make Yahoo! Web Service REST Calls With VB.NET
http://developer.yahoo.com/dotnet/howto-rest_vb.html

Imports System  
Imports System.IO  
Imports System.Net  
Imports System.Text  
  
Dim request As HttpWebRequest  
Dim response As HttpWebResponse = Nothing  
Dim reader As StreamReader  
  
Try  
    ' Create the web request  
    request = DirectCast(WebRequest.Create("http://developer.yahoo.com/"), HttpWebRequest)  
  
    ' Get response  
    response = DirectCast(request.GetResponse(), HttpWebResponse)  
  
    ' Get the response stream into a reader  
    reader = New StreamReader(response.GetResponseStream())  
  
    ' Console application output  
    Console.WriteLine(reader.ReadToEnd())  
Finally  
    If Not response Is Nothing Then response.Close()  
End Try  

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:jking1234
ID: 35200491
I adapted your code as follows and get the following message:
++++++++++++++++
Imports System
Imports System.Net
Imports System.IO

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader

        Try
            ' Create the web request  
            request = DirectCast(WebRequest.Create("http://api.adnxs.com/auth"), HttpWebRequest)

            ' Get response  
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Get the response stream into a reader  
            reader = New StreamReader(response.GetResponseStream())

            ' Console application output  
            MessageBox.Show(reader.ReadToEnd())
        Finally
            If Not response Is Nothing Then response.Close()
        End Try

    End Sub
End Class
+++++++++++++++
MESSAGE:
"{"response":{"error_id":"SYSTEM","error":"Username or password not set on request","error_description":"the username\/password value is not valid","error_code":"INVALID_LOGIN","service":"auth","method":"GET","dbg":{"instance":"10.api.prod.nym1","slave_hit":false,"db":"master","time":2.7751922607422}}} "

Can you suggest some code to give username password then recieve/ and use the token

TIA
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 35200582
If you look at that same article, there are multiple pieces of code.  You need the one that defines the credentials for the request.

request.Credentials = New NetworkCredential("username", "password")  

Open in new window

0
 

Author Closing Comment

by:jking1234
ID: 35205726
I must learn to read complete replies!
Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35205916
"All learning IS good" in my opinion!!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Definitions and default visual studio colors 5 65
vb.net 2 43
how to wrap a merged cells of datagridview column in vs2010 (vb.net) 8 34
vb.net class 3 17
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question