An alternative to UBB.threads
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FLocal/Importer/ShallerConnector.cs

49 lines
1.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.Configuration;
using System.IO;
namespace FLocal.Importer {
class ShallerConnector {
public static string getPageContent(string requestUrl, Dictionary<string, string> postData, CookieContainer cookies) {
string baseUrl = ConfigurationManager.AppSettings["Importer_BaseUrl"];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUrl + requestUrl);
request.KeepAlive = true;
request.CookieContainer = cookies;
if(postData.Count < 1) {
request.Method = "GET";
} else {
StringBuilder postBuilder = new StringBuilder();
foreach(KeyValuePair<string, string> kvp in postData) {
postBuilder.Append(HttpUtility.UrlEncode(kvp.Key));
postBuilder.Append('=');
postBuilder.Append(HttpUtility.UrlEncode(kvp.Value));
}
byte[] postBytes = Encoding.ASCII.GetBytes(postBuilder.ToString());
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(postBytes, 0, postBytes.Length);
stream.Close();
}
request.UserAgent = "ShallerConnector v0.1";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies.Add(response.Cookies);
using(StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1251))) {
return reader.ReadToEnd();
}
}
}
}