c# - Accessing and getting response from API call -
i checking out namecheap api , having difficulty getting started. trying access api after setting sandbox account etc , sample response in xml format:
<apiresponse status="ok" xmlns="http://api.namecheap.com/xml.response"> <errors /> <warnings /> <requestedcommand>namecheap.domains.check</requestedcommand> <commandresponse> <domaincheckresult domain="google.com" available="false" /> </commandresponse> <server>web1-sandbox1</server> <gmttimedifference>--4:00</gmttimedifference> <executiontime>0.875</executiontime> </apiresponse>
i know how parse xml, need little guidance how started actual request/response part of api call.
i know parameters need send, , know need api key , url, how write webrequest , webresponse part of it? or can linq provide me way achieve too?
i trying use:
webrequest req = httpwebrequest.create(url + apikey + username + command + domain); webresponse response = req.getresponse();
but don't see way variable response
.
how can make simple api call api , response xml format can parse it?
any @ appreciated.
you need response stream associated , read it:
// stream associated response. stream receivestream = response.getresponsestream (); streamreader readstream = new streamreader (receivestream, encoding.utf8); console.writeline ("response stream received."); console.writeline (readstream.readtoend ());
Comments
Post a Comment