Removed SendRequestJSON method

This commit is contained in:
Jaex 2016-12-23 10:55:16 +03:00
parent a0434e8c91
commit 10b57f05e3
7 changed files with 13 additions and 35 deletions

View file

@ -153,7 +153,7 @@ public virtual void StopUpload()
} }
} }
protected string SendRequest(HttpMethod method, string url, string content, Dictionary<string, string> args = null, NameValueCollection headers = null, protected string SendRequest(HttpMethod method, string url, string content, string contentType = null, Dictionary<string, string> args = null, NameValueCollection headers = null,
CookieCollection cookies = null, ResponseType responseType = ResponseType.Text) CookieCollection cookies = null, ResponseType responseType = ResponseType.Text)
{ {
byte[] data = Encoding.UTF8.GetBytes(content); byte[] data = Encoding.UTF8.GetBytes(content);
@ -162,7 +162,7 @@ public virtual void StopUpload()
{ {
ms.Write(data, 0, data.Length); ms.Write(data, 0, data.Length);
return SendRequest(method, url, ms, null, args, headers, cookies, responseType); return SendRequest(method, url, ms, contentType, args, headers, cookies, responseType);
} }
} }
@ -175,7 +175,7 @@ public virtual void StopUpload()
} }
} }
protected bool SendRequest(HttpMethod method, Stream downloadStream, string url, Dictionary<string, string> args = null, protected bool SendRequestDownload(HttpMethod method, string url, Stream downloadStream, Dictionary<string, string> args = null,
NameValueCollection headers = null, CookieCollection cookies = null, string contentType = null) NameValueCollection headers = null, CookieCollection cookies = null, string contentType = null)
{ {
using (HttpWebResponse response = GetResponse(method, url, null, contentType, args, headers, cookies)) using (HttpWebResponse response = GetResponse(method, url, null, contentType, args, headers, cookies))
@ -190,26 +190,6 @@ public virtual void StopUpload()
return false; return false;
} }
protected string SendRequestJSON(string url, string json, NameValueCollection headers = null, CookieCollection cookies = null, HttpMethod method = HttpMethod.POST)
{
MemoryStream stream = null;
try
{
if (!string.IsNullOrEmpty(json))
{
byte[] data = Encoding.UTF8.GetBytes(json);
stream = new MemoryStream(data);
}
return SendRequest(method, url, stream, ContentTypeJSON, null, headers, cookies);
}
finally
{
if (stream != null) stream.Dispose();
}
}
protected string SendRequestURLEncoded(string url, Dictionary<string, string> args, NameValueCollection headers = null, CookieCollection cookies = null, protected string SendRequestURLEncoded(string url, Dictionary<string, string> args, NameValueCollection headers = null, CookieCollection cookies = null,
HttpMethod method = HttpMethod.POST, ResponseType responseType = ResponseType.Text) HttpMethod method = HttpMethod.POST, ResponseType responseType = ResponseType.Text)
{ {

View file

@ -120,7 +120,7 @@ public bool DownloadFile(string path, Stream downloadStream)
{ {
string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path)); string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path));
string query = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo); string query = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo);
return SendRequest(HttpMethod.GET, downloadStream, query); return SendRequestDownload(HttpMethod.GET, query, downloadStream);
} }
return false; return false;

View file

@ -71,9 +71,9 @@ public Ge_ttLogin Login(string email, string password)
args.Add("email", email); args.Add("email", email);
args.Add("password", password); args.Add("password", password);
string argsJSON = JsonConvert.SerializeObject(args); string json = JsonConvert.SerializeObject(args);
string response = SendRequestJSON("https://open.ge.tt/1/users/login", argsJSON); string response = SendRequest(HttpMethod.POST, "https://open.ge.tt/1/users/login", json, ContentTypeJSON);
return JsonConvert.DeserializeObject<Ge_ttLogin>(response); return JsonConvert.DeserializeObject<Ge_ttLogin>(response);
} }
@ -94,14 +94,12 @@ public Ge_ttFile CreateFile(string accessToken, string shareName, string fileNam
Dictionary<string, string> args = new Dictionary<string, string>(); Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("accesstoken", accessToken); args.Add("accesstoken", accessToken);
string url = CreateQuery(string.Format("https://open.ge.tt/1/files/{0}/create", shareName), args);
Dictionary<string, string> args2 = new Dictionary<string, string>(); Dictionary<string, string> args2 = new Dictionary<string, string>();
args2.Add("filename", fileName); args2.Add("filename", fileName);
string argsJSON = JsonConvert.SerializeObject(args2); string json = JsonConvert.SerializeObject(args2);
string response = SendRequestJSON(url, argsJSON); string response = SendRequest(HttpMethod.POST, $"https://open.ge.tt/1/files/{shareName}/create", json, ContentTypeJSON, args);
return JsonConvert.DeserializeObject<Ge_ttFile>(response); return JsonConvert.DeserializeObject<Ge_ttFile>(response);
} }

View file

@ -217,7 +217,7 @@ private void SetPermissions(string fileID, GoogleDrivePermissionRole role, Googl
withLink = withLink.ToString() withLink = withLink.ToString()
}); });
string response = SendRequestJSON(url, json, GetAuthHeaders()); string response = SendRequest(HttpMethod.POST, url, json, ContentTypeJSON, null, GetAuthHeaders());
} }
public List<GoogleDriveFile> GetFolders(bool trashed = false, bool writer = true) public List<GoogleDriveFile> GetFolders(bool trashed = false, bool writer = true)

View file

@ -152,7 +152,7 @@ public override UploadResult Upload(Stream stream, string fileName)
public string PostRequestJson(Uri url, string jsonData) public string PostRequestJson(Uri url, string jsonData)
{ {
return SendRequestJSON(url.ToString(), jsonData); return SendRequest(HttpMethod.POST, url.ToString(), jsonData, ContentTypeJSON);
} }
public string PostRequestRaw(Uri url, Stream dataStream) public string PostRequestRaw(Uri url, Stream dataStream)

View file

@ -132,7 +132,7 @@ public override UploadResult UploadText(string text, string fileName)
} }
}; };
string argsJson = JsonConvert.SerializeObject(gistUploadObject); string json = JsonConvert.SerializeObject(gistUploadObject);
string url = URLGists; string url = URLGists;
@ -141,7 +141,7 @@ public override UploadResult UploadText(string text, string fileName)
url += "?access_token=" + AuthInfo.Token.access_token; url += "?access_token=" + AuthInfo.Token.access_token;
} }
string response = SendRequestJSON(url, argsJson); string response = SendRequest(HttpMethod.POST, url, json, ContentTypeJSON);
if (response != null) if (response != null)
{ {

View file

@ -183,7 +183,7 @@ public override UploadResult ShortenURL(string url)
string json = JsonConvert.SerializeObject(new { longUrl = url }); string json = JsonConvert.SerializeObject(new { longUrl = url });
result.Response = SendRequestJSON(query, json); result.Response = SendRequest(HttpMethod.POST, query, json, ContentTypeJSON);
if (!string.IsNullOrEmpty(result.Response)) if (!string.IsNullOrEmpty(result.Response))
{ {