connect to web API from ..NET
- by Saif Khan
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.