Solved

VB.net REST API

Posted on 2011-03-22
7
1,484 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

626 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