本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.ToString方法的具体用法?C# NameValueCollection.ToString怎么用?C# NameValueCollection.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public void Login(string loginPageAddress, NameValueCollection loginData)
{
CookieContainer container;
var request = (HttpWebRequest)WebRequest.Create(loginPageAddress);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
var buffer = Encoding.ASCII.GetBytes(loginData.ToString());
request.ContentLength = buffer.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
container = request.CookieContainer = new CookieContainer();
var response = request.GetResponse();
var stmr = new StreamReader(response.GetResponseStream());
var json = stmr.ReadToEnd();
readtofile(json);
//if (json.Contains("loginphrase"))
//{
// MessageBox.Show("Invalid Username or Password", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
//else
//{
//}
response.Close();
CookieContainer = container;
}
示例2: EbexeForward
public static void EbexeForward(NameValueCollection queryString)
{
string remoteUrl = MarcosServerUri.ToString() +
"edms/exe/eb.exe?" + queryString.ToString();
GetUrl(remoteUrl, true);
}
示例3: MakeYoutubeAuthorizationRequest
public string MakeYoutubeAuthorizationRequest(NameValueCollection queryString, HttpClient httpClient)
{
var authUrl = "https://accounts.google.com/o/oauth2/token";
var content = new StringContent(queryString.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");
var exchangePostResponse = httpClient.PostAsync(authUrl, content).Result;
var resp = exchangePostResponse.Content.ReadAsStringAsync().Result;
return resp;
}
示例4: Execute
/// <summary>
///
/// </summary>
/// <param name="postCollection"></param>
/// <returns></returns>
private string Execute(NameValueCollection postCollection)
{
var request = WebRequest.Create(ServiceUrl);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = WebRequestMethods.Http.Post;
postCollection["file"] = "json";
postCollection["f"] = "get_data";
var postData = postCollection.ToString();
var byteArray = new ASCIIEncoding().GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream stream = null;
StreamReader streamReader = null;
WebResponse response = null;
try
{
// POST REQUEST
stream = request.GetRequestStream();
stream.Write(byteArray, 0, byteArray.Length);
stream.Close();
// GET RESPONSE
response = request.GetResponse();
stream = response.GetResponseStream();
// READ RESPONSE
streamReader = new StreamReader(stream);
var responseFromServer = streamReader.ReadToEnd();
// RETURN RESPONSE
return responseFromServer;
}
finally
{
if (streamReader != null)
streamReader.Close();
if (stream != null)
stream.Close();
if (response != null)
response.Close();
}
}
示例5: CreateRequest
private HttpWebRequest CreateRequest(string relativePath, NameValueCollection queryStringCollection = null)
{
if (relativePath == null)
{
throw new ArgumentNullException("relativePath");
}
queryStringCollection = queryStringCollection ?? CreateQueryStringCollection();
queryStringCollection.Add("key", this.key);
var uri = this.urlBase + relativePath + "?" + queryStringCollection.ToString();
var request = WebRequest.CreateHttp(uri);
return request;
}
示例6: PostToImgur
public void PostToImgur(string filename)
{
changeValueEnabled();
Bitmap bitmap = new Bitmap(filename);
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Jpeg);
using (var w = new WebClient())
{
w.UploadProgressChanged += new UploadProgressChangedEventHandler(delegate(object send, UploadProgressChangedEventArgs arg)
{
int percent = arg.ProgressPercentage;
progressBar.Value = percent > 0 ? (percent < 45 ? percent * 2 : (percent >= 90 ? percent : 90)) : 0;
});
this.FormClosing += new FormClosingEventHandler(delegate(object send, FormClosingEventArgs arg)
{
w.CancelAsync();
});
var values = new NameValueCollection
{
{ "key", IMGUR_API_KEY },
{ "image", Convert.ToBase64String(memoryStream.ToArray()) }
};
string debug = values.ToString();
byte[] response = new byte[0];
w.UploadValuesCompleted += new UploadValuesCompletedEventHandler(delegate(object send, UploadValuesCompletedEventArgs arg)
{
if (arg.Cancelled) return;
response = arg.Result;
XDocument xDocument = XDocument.Load(new MemoryStream(response));
bitmap.Dispose();
_address = (string)xDocument.Root.Element("original_image");
this.Close();
});
w.UploadValuesAsync(new Uri("http://imgur.com/api/upload.xml"), values);
buttonClose.Click -= buttonClose_Click;
buttonClose.Click += new EventHandler(delegate(object send, EventArgs arg)
{
w.CancelAsync();
changeValueEnabled();
buttonClose.Click += buttonClose_Click;
});
}
}
示例7: Login
public void Login(string loginPageAddress, NameValueCollection loginData)
{
CookieContainer container;
var request = (HttpWebRequest)WebRequest.Create(loginPageAddress);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
var buffer = Encoding.ASCII.GetBytes(loginData.ToString());
request.ContentLength = buffer.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
container = request.CookieContainer = new CookieContainer();
var response = request.GetResponse();
response.Close();
CookieContainer = container;
}
示例8: NameValueListFieldWrapper
public NameValueListFieldWrapper(string key, ref ItemWrapper item, ISpawnProvider spawnProvider, ArrayList value = null)
: base(key, ref item, string.Empty, spawnProvider)
{
if (value == null)
{
return;
}
_value = new NameValueCollection();
foreach (object val in value)
{
if (val is ArrayList)
{
var tmp = val as ArrayList;
_value.Add(tmp[0].ToString(), tmp[1].ToString());
}
}
this._rawValue = _value.ToString();
}
示例9: DoLogin
public void DoLogin(string loginUrl, NameValueCollection loginData)
{
CookieContainer container;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginUrl);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] buffer = Encoding.UTF8.GetBytes(loginData.ToString());
request.ContentLength = buffer.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
container = request.CookieContainer = new CookieContainer();
WebResponse response = request.GetResponse();
response.Close();
CookieContainer = container;
}
示例10: Put
public async Task<Uri> Put(Stream stream, TimeSpan? timeToLive = null, CancellationToken cancellationToken = new CancellationToken())
{
string keyId = null;
using (Stream cryptoStream = _streamProvider.GetEncryptStream(stream, keyId, CryptoStreamMode.Read))
{
var address = await _repository.Put(cryptoStream, timeToLive, cancellationToken).ConfigureAwait(false);
var addressBuilder = new UriBuilder(address);
NameValueCollection parameters = new NameValueCollection();
if (!string.IsNullOrWhiteSpace(addressBuilder.Query))
{
var query = addressBuilder.Query;
if (query.Contains("?"))
{
query = query.Substring(query.IndexOf('?') + 1);
}
foreach (string parameter in query.Split('&'))
{
if (string.IsNullOrWhiteSpace(parameter))
continue;
string[] pair = parameter.Split('=');
parameters.Add(pair[0], pair.Length == 2 ? pair[1] : "");
}
}
parameters["keyId"] = "";
addressBuilder.Query = parameters.ToString();
return addressBuilder.Uri;
}
}
示例11: AddVisitorAsync
/// <summary>
/// Add visitor data to a shortened url.
/// </summary>
/// <param name="id">Short Url Id</param>
/// <param name="headers">request headers</param>
/// <param name="userAgent">request user agent</param>
/// <returns></returns>
public async Task AddVisitorAsync(int id, NameValueCollection headers, string userAgent)
{
var visitor = Visitors.Create();
visitor.ShortUrlId = id;
visitor.Agent = userAgent;
visitor.Created = DateTime.UtcNow;
visitor.Headers = headers.ToString();
Visitors.Add(visitor);
await SaveChangesAsync();
}
示例12: buildRequestAndExecute
/**
* This method builds an HTTP request and executes it.
* @param parameters this is a collection holding the key value pair of the data to be sent as part of the request
* @param action this is the resource (or the endpoint) we are looking for. It could be customer, shipping or order
*/
private void buildRequestAndExecute(NameValueCollection parameters, string action)
{
string toencode = "";
foreach(String entry in parameters.AllKeys)
{
toencode += parameters[entry] + ".";
}
toencode = toencode.Substring(0, toencode.Length - 1);
var messageBytes = encoding.GetBytes(toencode);
this._hmacmd5.ComputeHash(messageBytes);
parameters.Add("hash",ByteToString(this._hmacmd5.Hash));
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://api.nitrosell.com/" + this._webstoreUrl + "/v1/"+action+".json");
request.Method = "POST";
string postData = parameters.ToString();
byte[] byteArray = encoding.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.UserAgent = "Mozilla/5.0";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
try
{
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
} catch(WebException e)
{
Console.WriteLine("Error in the request Code : {0}", e.Message);
}
}
示例13: GetTabFromDictionary
internal static string GetTabFromDictionary(string url, NameValueCollection querystringCol, FriendlyUrlSettings settings, UrlAction result, Guid parentTraceId)
{
//retrive the tab dictionary from the cache and get the path depth values
int maxAliasPathDepth;
int maxTabPathDepth;
int minAliasPathDepth;
int minTabPathDepth;
bool triedFixingSubdomain = false;
int curAliasPathDepth = 0;
var tabDict = TabIndexController.FetchTabDictionary(result.PortalId,
out minTabPathDepth,
out maxTabPathDepth,
out minAliasPathDepth,
out maxAliasPathDepth,
settings,
false,
result.BypassCachedDictionary,
parentTraceId);
//clean up and prepare the url for scanning
if (url.EndsWith("/"))
{
url = url.TrimEnd('/');
}
//ok now scan for the language modifier
string langParms = CheckLanguageMatch(ref url, result);
//clean off the extension before checking the url matches, but
//remember if an extension existed
bool hadExtension;
string cleanUrl = CleanExtension(url, settings, langParms, out hadExtension);
string[] splitUrl = cleanUrl.Split('/');
//initialise logic switches
bool reWritten = false;
bool finished = false;
string newUrl = CheckIfPortalAlias(url, querystringCol, result, settings, tabDict);
if (newUrl != url)
{
finished = true;
reWritten = true;
}
//start looping through the url segments looking for a match in the tab dictionary
while (finished == false)
{
//first, try forming up a key based on alias/tabpath
int lastIndex = splitUrl.GetUpperBound(0);
int arraySize = lastIndex + 1;
int totalDepth = maxAliasPathDepth + 1 + maxTabPathDepth + 1;
//the maximum depth of segments of a valid url
for (int i = lastIndex; i >= 0; i += -1)
{
//only start checking the url when it is in the range of the min->max number of segments
if ((i > minAliasPathDepth & i <= totalDepth))
{
//join all the tab path sections together
//flag to remember if the incoming path had a .aspx or other pageAndExtension on it
int tabPathStart = curAliasPathDepth + 1;
int tabPathLength = i - curAliasPathDepth;
if ((tabPathStart + tabPathLength) <= arraySize)
{
string tabPath = "";
if ((tabPathLength > -1))
{
tabPath = string.Join("/", splitUrl, tabPathStart, tabPathLength);
}
string aliasPath;
if ((curAliasPathDepth <= lastIndex))
{
aliasPath = string.Join("/", splitUrl, 0, curAliasPathDepth + 1);
}
else
{
finished = true;
break;
}
int parmsSize = lastIndex - i;
int parmStart = i + 1; //determine if any parameters on this value
//make up the index that is looked for in the Tab Dictionary
string urlPart = aliasPath + "::" + tabPath;
//the :: allows separation of pagename and portal alias
string tabKeyVal = urlPart.ToLower(); //force lower case lookup, all keys are lower case
//Try with querystring first If last Index
bool found = false;
if (querystringCol.Count > 0)
{
found = CheckTabPath(tabKeyVal + "?" + querystringCol.ToString().Split('&')[0].ToLowerInvariant(), result, settings, tabDict, ref newUrl);
}
if (!found)
{
found = CheckTabPath(tabKeyVal, result, settings, tabDict, ref newUrl);
}
//.........这里部分代码省略.........
示例14: BuildUrl
/// <summary>
/// Builds a url from a base url (which can contains protocol and uri or be a relative url and optionaly query string) and additional query string
/// </summary>
/// <param name="baseUrl">The base url</param>
/// <param name="queryStringParams">The additional query string values</param>
/// <returns>The URL</returns>
protected virtual string BuildUrl(string baseUrl, NameValueCollection queryStringParams)
{
if (queryStringParams.Count < 1)
{
return baseUrl;
}
if (baseUrl.IndexOf("?") > -1)
{
queryStringParams.Add(HttpUtility.ParseQueryString(baseUrl.Substring(baseUrl.IndexOf("?"))));
baseUrl = baseUrl.Substring(0, baseUrl.IndexOf("?"));
}
return baseUrl + "?" + queryStringParams.ToString();
}
示例15: CreateNavigationGrid
public static IHtmlString CreateNavigationGrid(this System.Web.Mvc.HtmlHelper html, ModelGrillaBase model)
{
NameValueCollection querystr = new NameValueCollection();
querystr = html.ViewContext.RequestContext.HttpContext.Request.QueryString;
string querystring = querystr.ToString();
if (querystring.IndexOf("page") > -1)
{
querystring = querystring.Remove(0, querystring.IndexOf('&') + 1);
}
var controller = html.ViewContext.RouteData.Values["controller"].ToString();
var action = html.ViewContext.RouteData.Values["action"].ToString();
int cantPages = (int)Math.Ceiling(Convert.ToDouble(model.Cantidad) / Convert.ToDouble(model.CantidadPorPagina));
StringBuilder sb = new StringBuilder();
TagBuilder tbTable = new TagBuilder("table");
tbTable.AddCssClass("controles-paginacion-grid");
tbTable.MergeAttribute("align", "right");
TagBuilder tbTr = new TagBuilder("tr");
string imgprevsrc = new UrlHelper(html.ViewContext.RequestContext).Content("~/Content/images/btn_prev.png");
string imgPrev = TagImage(imgprevsrc, LenceriaKissy.Recursos.AppResources.Vistas.Anterior);
string imgnextsrc = new UrlHelper(html.ViewContext.RequestContext).Content("~/Content/images/btn_next.png");
string imgNext = TagImage(imgnextsrc, LenceriaKissy.Recursos.AppResources.Vistas.Siguiente);
if (model.PaginaActual > 1)
{
TagBuilder tbTd = new TagBuilder("td");
string link = (new UrlHelper(html.ViewContext.RequestContext)).Action(action, new { page = model.PaginaActual - 1 });
link += "&" + querystring.ToString();
TagBuilder tbAnchor = new TagBuilder("a");
tbAnchor.MergeAttribute("href", link);
tbAnchor.InnerHtml = imgPrev;
tbTd.InnerHtml = LenceriaKissy.Recursos.AppResources.Vistas.Anterior + tbAnchor.ToString();
tbTr.InnerHtml += tbTd.ToString();
}
else {
TagBuilder tbTd = new TagBuilder("td");
tbTd.InnerHtml = LenceriaKissy.Recursos.AppResources.Vistas.Anterior + imgPrev;
tbTr.InnerHtml += tbTd.ToString();
}
for (int i = 1; i <= cantPages; i++)
{
if ((i > (model.PaginaActual - 4)) && (i <= (model.PaginaActual + 3)) || (i == 1) || (i == cantPages))
{
if (i == model.PaginaActual)
{
TagBuilder tbTd = new TagBuilder("td");
tbTd.InnerHtml += model.PaginaActual.ToString();
tbTr.InnerHtml += tbTd.ToString();
}
if (i > model.PaginaActual)
{
if ((i == cantPages) && !(i <= (model.PaginaActual + 4)))
{
TagBuilder tagpunt = new TagBuilder("td");
tagpunt.InnerHtml += "..";
tbTr.InnerHtml += tagpunt.ToString();
}
TagBuilder tbTd = new TagBuilder("td");
string link = new UrlHelper(html.ViewContext.RequestContext).Action(action, new { page = i });
link += "&" + querystring;
TagBuilder tbAnchor = new TagBuilder("a");
tbAnchor.MergeAttribute("href", link);
tbAnchor.InnerHtml = i.ToString();
tbTd.InnerHtml += tbAnchor.ToString();
tbTr.InnerHtml += tbTd.ToString();
}
if (i < model.PaginaActual)
{
TagBuilder tbTd = new TagBuilder("td");
string link = new UrlHelper(html.ViewContext.RequestContext).Action(action, new { page = i });
link += "&" + querystring;
TagBuilder tbAnchor = new TagBuilder("a");
tbAnchor.MergeAttribute("href", link);
tbAnchor.InnerHtml = i.ToString();
tbTd.InnerHtml += tbAnchor.ToString();
tbTr.InnerHtml += tbTd.ToString();
if ((i == 1) && !(i > (model.PaginaActual - 5)))
{
TagBuilder tagpunt = new TagBuilder("td");
tagpunt.InnerHtml += "..";
tbTr.InnerHtml += tagpunt.ToString();
}
}
}
}
if (cantPages > model.PaginaActual)
{
TagBuilder tbTd = new TagBuilder("td");
string link = (new UrlHelper(html.ViewContext.RequestContext)).Action(action, new { page = model.PaginaActual + 1 });
//.........这里部分代码省略.........