Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Web;
- namespace TwitterRequest
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class Twitter : Window
- {
- string twitterUserName = "oetsieloetsie";
- string twitterPassword = "toettoetboingboing";
- public Twitter()
- {
- InitializeComponent();
- }
- private void requestAnswerClick(object sender, RoutedEventArgs e)
- {
- HttpWebRequest request;
- HttpWebResponse response = null;
- StreamReader reader;
- StringBuilder sbSource;
- Uri address = new Uri("http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction");
- if (address == null) { throw new ArgumentNullException("address"); }
- try
- {
- // Create and initialize the web request
- request = WebRequest.Create(address) as HttpWebRequest;
- request.UserAgent = ".NET Sample";
- request.KeepAlive = false;
- // Set timeout to 15 seconds
- request.Timeout = 15 * 1000;
- // Get response
- response = request.GetResponse() as HttpWebResponse;
- if (request.HaveResponse == true && response != null)
- {
- // Get the response stream
- reader = new StreamReader(response.GetResponseStream());
- // Read it into a StringBuilder
- sbSource = new StringBuilder(reader.ReadToEnd());
- // Console application output
- respondAnswer.Text = sbSource.ToString();
- }
- }
- catch (WebException wex)
- {
- // This exception will be raised if the server didn't return 200 - OK
- // Try to retrieve more information about the network error
- if (wex.Response != null)
- {
- using (HttpWebResponse errorResponse = (HttpWebResponse)wex.Response)
- {
- Console.WriteLine(
- "The server returned '{0}' with the status code {1} ({2:d}).",
- errorResponse.StatusDescription, errorResponse.StatusCode,
- errorResponse.StatusCode);
- }
- }
- }
- finally
- {
- if (response != null) { response.Close(); }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement