Solved

VB.net REST API

Posted on 2011-03-22
7
1,422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert datetime to time string 10 34
MailAddress in vb 4 36
ASP.NET (VB) return a record 2 51
run a stored procedure from vb.net 1 31
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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