mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Changes for Box Plugin so it can re-use the OAuthLoginForm. Also fixed a startup issue with some plug-ins.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2143 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
dc8a160c7f
commit
69d29992a2
8 changed files with 74 additions and 54 deletions
|
@ -49,25 +49,16 @@ namespace GreenshotPlugin.Core {
|
|||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Download a file as string
|
||||
/// Download a url response as string
|
||||
/// </summary>
|
||||
/// <param name=url">An Uri to specify the download location</param>
|
||||
/// <param name=encoding">The encoding to use</param>
|
||||
/// <returns>string with the file content</returns>
|
||||
public static string DownloadFileAsString(Uri url, Encoding encoding) {
|
||||
try {
|
||||
HttpWebRequest request = (HttpWebRequest)CreateWebRequest(url);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
if (request.HaveResponse) {
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) {
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Problem downloading from: " + url.ToString(), e);
|
||||
}
|
||||
return null;
|
||||
public static string GetAsString(Uri url) {
|
||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
webRequest.Method = "GET";
|
||||
webRequest.KeepAlive = true;
|
||||
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
return GetResponse(webRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -290,9 +281,11 @@ namespace GreenshotPlugin.Core {
|
|||
public static string GetResponse(HttpWebRequest webRequest) {
|
||||
string responseData;
|
||||
try {
|
||||
using (StreamReader reader = new StreamReader(webRequest.GetResponse().GetResponseStream(), true)) {
|
||||
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream(), true)) {
|
||||
responseData = reader.ReadToEnd();
|
||||
}
|
||||
LOG.DebugFormat("Response status: {0}", response.StatusCode);
|
||||
} catch (WebException e) {
|
||||
HttpWebResponse response = (HttpWebResponse)e.Response;
|
||||
using (Stream responseStream = response.GetResponseStream()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue