C# webrequest example for Empire Avenue API?

122 views
Skip to first unread message

nixkuroi

unread,
Feb 24, 2012, 6:26:14 AM2/24/12
to Empire Avenue API Discussion
I've been trying to pound this out for days with no success. Does
anyone have a working example of a request for getting notifications
in c#?

Any help would be appreciated.

nixkuroi

unread,
Feb 28, 2012, 3:07:05 AM2/28/12
to Empire Avenue API Discussion
I guess not.

John S [ZZBOMB]

unread,
Mar 2, 2012, 1:16:44 AM3/2/12
to empireave-ap...@googlegroups.com
Should just be your standard C# GET_ request...

This looks like it would work, I dont work with C# though so I dont really have the environment setup to test it.
http://support.microsoft.com/kb/307023

Just adapt so that sURL == the url of your request.

Kevin Umbach

unread,
Mar 2, 2012, 3:42:31 PM3/2/12
to empireave-ap...@googlegroups.com
Try posting snippets of your C# code. We might not have much C#
experience here, but I bet someone might be able to offer some helpful
information...

Regards,
Kevin

Ulf Hedlund

unread,
Mar 2, 2012, 5:43:18 PM3/2/12
to empireave-ap...@googlegroups.com
On Fri, Feb 24, 2012 at 12:26 PM, nixkuroi <nixk...@gmail.com> wrote:
> I've been trying to pound this out for days with no success.  Does
> anyone have a working example of a request for getting notifications
> in c#?

Is it webrequest in general or just the request for notifications
that's the problem? The GET request should look something like this:

string HttpGet(string url)
{
HttpWebRequest req = WebRequest.Create(url)
as HttpWebRequest;
string result = null;
try
{
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
}
catch (Exception e)
{
// may want to handle this :)

throw e;
}
return result;
}

nixkuroi

unread,
Mar 2, 2012, 6:29:05 PM3/2/12
to Empire Avenue API Discussion
Kevin, Ulf and John,

Thanks for getting back to me and I was able to work it out on the
29th (yay leap day!). It's pretty similar to what Ulf has there
except I added a couple of lines for the SSL stuff that have appeared
to make the magic happen:


var credCache = new CredentialCache();
credCache.Add(new Uri(url), "Basic", new
NetworkCredential(username, password));
ServicePointManager.ServerCertificateValidationCallback =
new
System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
url = url + "?" + postData;

webRequest = System.Net.WebRequest.Create(url) as
HttpWebRequest;
webRequest.PreAuthenticate = true;
webRequest.Credentials = credCache;


Again, much appreciated!

Mike


On Mar 2, 2:43 pm, Ulf Hedlund <u...@ulfhedlund.se> wrote:

Ulf Hedlund

unread,
Mar 2, 2012, 8:25:30 PM3/2/12
to empireave-ap...@googlegroups.com
Good to hear that you found a solution. If you havnt already found a
good JSON parser, I like this one:

http://james.newtonking.com/pages/json-net.aspx

There are a few others but I've used this in several different
projects and like it.

Mike Simon

unread,
Mar 2, 2012, 8:52:04 PM3/2/12
to empireave-ap...@googlegroups.com
Ulf,

That's the exact library I'm using :)

Thanks for the suggestion.
:)

Mike

Reply all
Reply to author
Forward
0 new messages