Solved

VB.net REST API

Posted on 2011-03-22
7
1,400 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
Comment Utility
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
Comment Utility

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

Expert Comment

by:Bob Learned
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:jking1234
Comment Utility
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
Comment Utility
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
Comment Utility
I must learn to read complete replies!
Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
"All learning IS good" in my opinion!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

772 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

10 Experts available now in Live!

Get 1:1 Help Now