Solved

VB.net REST API

Posted on 2011-03-22
7
1,404 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now