connect to web API from ..NET

Posted by Saif Khan on Stack Overflow See other posts from Stack Overflow or by Saif Khan
Published on 2010-03-18T18:39:34Z Indexed on 2010/03/18 18:41 UTC
Read the original article Hit count: 423

Filed under:
|
|
|
|

How can I access and consume a web API from .NET? The API is not a .NET API. Here is sample code I have in Ruby

 require 'uri'
  require 'net/http'

  url = URI.parse("http://account.codebasehq.com/widgets/tickets")
  req = Net::HTTP::Post.new(url.path)
  req.basic_auth('dave', '6b2579a03c2e8825a5fd0a9b4390d15571f3674d')
  req.add_field('Content-type', 'application/xml')
  req.add_field('Accept', 'application/xml')

 xml = "<ticket><summary>My Example Ticket</summary><status-id>1234</status-id><priority-id>1234</priority-id><ticket-type>bug</ticket-type></ticket>"

 res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req, xml)}
 case res
 when Net::HTTPCreated
   puts "Record was created successfully."
 else
   puts "An error occurred while adding this record"
 end

Where can I find information on consuming API like this from .NET? I am aware how to use .NET webservices.

© Stack Overflow or respective owner

Related posts about web-api

Related posts about Xml