相关疑难解决方法(0)

Server.UrlEncode与HttpUtility.UrlEncode

Server.UrlEncode和HttpUtility.UrlEncode之间有区别吗?

.net asp.net urlencode

173
推荐指数
6
解决办法
14万
查看次数

为System.Net.HttpClient get构建查询字符串

如果我希望使用System.Net.HttpClient提交http get请求,似乎没有api添加参数,这是正确的吗?

是否有任何简单的api可用于构建查询字符串,该字符串不涉及构建名称值集合和url编码那些然后最终连接它们?我希望使用类似RestSharp的api(即AddParameter(..))

.net c# http

159
推荐指数
6
解决办法
14万
查看次数

如何将对象序列化为查询字符串格式?

如何将对象序列化为查询字符串格式?我似乎无法在谷歌上找到答案.谢谢.

这是我将序列化的对象作为示例.

public class EditListItemActionModel
{
    public int? Id { get; set; }
    public int State { get; set; }
    public string Prefix { get; set; }
    public string Index { get; set; }
    public int? ParentID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

asp.net serialization object query-string

61
推荐指数
5
解决办法
5万
查看次数

在C#中将查询字符串转换为字典的最佳方法

我正在寻找将查询字符串从HTTP GET请求转换为字典的最简单方法,然后再返回.

我认为一旦它以字典形式对查询进行各种操作就会更容易,但我似乎有很多代码只是为了进行转换.有推荐的方法吗?

c#

56
推荐指数
9
解决办法
4万
查看次数

如何在C#中更新查询字符串?

在网址的某处有一个&sortBy = 6.如何在单击按钮时将其更新为&sortBy = 4或&sortBy = 2?我是否需要编写自定义字符串函数来创建正确的重定向网址?

如果我只需要附加一个查询字符串变量,我会这样做

string completeUrl = HttpContext.Current.Request.Url.AbsoluteUri + "&" + ...
Response.Redirect(completeUrl);
Run Code Online (Sandbox Code Playgroud)

但我想要做的是修改现有的querystring变量.

c# asp.net query-string

45
推荐指数
3
解决办法
9万
查看次数

Windows Phone 7中的HttpUtility.UrlEncode?

常规的.Net框架在System.Web程序集中包含HttpUtility.UrlEncode,在Silverlight中,它似乎被移动到System.Windows.Browser.但是在Windows Phone 7中(我认为它与Silverlight相同)我似乎无法找到适当的方式来UrlEncode.Windows Phone 7环境中既没有前面提到的程序集也可用.

c# silverlight windows-phone-7

34
推荐指数
2
解决办法
2万
查看次数

在C#中输出一个被操纵的QueryString

使用以下代码我得到一个很好的格式化字符串:

Request.QueryString.ToString 
Run Code Online (Sandbox Code Playgroud)

给我一些像:&hello = worldµsoft =糟透了

但是,当我使用此代码将集合克隆到另一个对象(相同类型)时,我从ToString()方法返回Type().

System.Collections.Specialized.NameValueCollection variables = new System.Collections.Specialized.NameValueCollection(Request.QueryString);
if (!string.IsNullOrEmpty(variables["sid"]))
    variables.Remove("sid");
Response.Write(variables.ToString());
Run Code Online (Sandbox Code Playgroud)

是否有更整洁的方式输出它而不是手动查看和构建字符串?

c# asp.net collections query-string

23
推荐指数
2
解决办法
2万
查看次数

如何编写HTTP请求

您好我尝试在C#(Post)中编写HTTP请求,但我需要有关错误的帮助

Expl:我想将DLC文件的内容发送到服务器并重新发送解密的内容.

C#代码

public static void decryptContainer(string dlc_content) 
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dcrypt.it/decrypt/paste");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

    using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
    {
        writer.Write("content=" + dlc_content);
    }

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        Console.WriteLine(reader.ReadToEnd());
    }
}
Run Code Online (Sandbox Code Playgroud)

在这里我收到了html请求

<form action="/decrypt/paste" method="post">
    <fieldset>
        <p class="formrow">
          <label for="content">DLC content</label>
          <input id="content" name="content" type="text" value="" />
         </p>
        <p class="buttonrow"><button type="submit">Submit »</button></p>
    </fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)

错误信息:

{
    "form_errors": {
      "__all__": [
        "Sorry, an error …
Run Code Online (Sandbox Code Playgroud)

c# post httprequest

13
推荐指数
2
解决办法
8万
查看次数

HttpUtility.ParseQueryString的反向函数

.Net的System.Web.HttpUtility类定义了以下函数来将查询字符串解析为NameValueCollection:

public static NameValueCollection ParseQueryString(string query);
Run Code Online (Sandbox Code Playgroud)

是否有任何功能可以反向(即将a NameValueCollection转换为查询字符串)?

asp.net asp.net-mvc namevaluecollection query-string

11
推荐指数
2
解决办法
6651
查看次数

在c#中构建字符串的优雅方式

使用keyvaluepair构建的字符串是这样的:"name1 = v1&name2 = v2&name3 = v3"

我在做什么:

var sb = new StringBuilder();

foreach (var name in nameValues)
{
            sb.AppendFormat("{0}={1}&", name.Key, name.Value);
 } 

//remove last '&' sign, this is what i think is ugly
sb.ToString().Remove(lastIndex);
Run Code Online (Sandbox Code Playgroud)

任何优雅的方法,以避免'&'符号的最后删除声明?

c# stringbuilder

10
推荐指数
2
解决办法
950
查看次数