TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nur Izzah Mohammad
NA
10
494
I got response.StatusCode as 'forbidden'
Nov 8 2019 5:13 AM
Hi Experts,
I have question on how to access web API from WPF. I am very new in this and just figure things out by google topics that I think related to what I need. Basically I need to create WPF application using c# showing list of cafe thats taken from server-side API(documented) and need to use ping to decide which cafe is the nearest.
If you have any resources that can help me with API and ping topics its much appreciated. I have 2 days to figure out everything.
I have yet to figure out the ping part, I just want to retrieve data to WPF from the API but I got status error 'forbiden'. I use below code:
System.Net.ServerPointManager.ServerCertificateValidationCallback = delegate { return true; };
HttpClient client = new HttpClient {
BaseAddress = new Uri("httpsxxx.apiary.io/")
} ;
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("locations").Result;
if (response.IsSuccessStatusCode) {
var location1 = response.Content.ReadAsAsync<IEnumerable<>>().Result;
grdLocation.ItemSource = location1;
}
else {
MessageBox.Show("Error happen" + response.StatusCode);
}
Please help. Thank very much in advance!
Reply
Answers (
3
)
ListView button click event
Resize the font in a datagrid cell so it fits the cell.