带有字符串的帖子的问题&在c#中

时间:2018-03-05 15:23:19

标签: c# webclient

我正在尝试向网址发帖,这应该看起来像小提琴手身上的图像。

来自fiddler的正确帖子

enter image description here

问题发生:当我将其发布时从& (&符号)并在fiddler体中为键值创建单独的条目。

我在fiddler的帖子

enter image description here

我该怎么做才能出现在单键值对中?

我想发布以下数据:

responseData = "paymentid=100131806470125606&result=NOT+CAPTURED&auth=138601&ref=806420053674&tranid=131806429899386&postdate=0305&trackid=100001182618838&udf1=1&udf2=2&udf3=3&udf4=4&udf5=5&amt=5190.0&authRespCode=51"


        using (WebClient wc = new WebClient())
        {
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string HtmlResult = wc.UploadString("https://example.com/test.php", "authRespCode=1&responseData = " + responseData);
        }

3 个答案:

答案 0 :(得分:0)

您可以使用HttpUtility.ParseQueryString

var res = HttpUtility.ParseQueryString(responseData);

然后你可以像这样访问你的参数:

res["paymentid"]

等...

答案 1 :(得分:0)

您需要转义URI字符串:

string HtmlResult = wc.UploadString("https://example.com/test.php", "authRespCode=1&responseData = " + Uri.EscapeUriString(responseData));

答案 2 :(得分:0)

添加此行解决了我的问题:

responseData = responseData.Replace("&", "&");
responseData = HttpUtility.UrlEncode(responseData);

完整代码:

string responseData = Utilitycl.GetHtmlInputValue(getString, "responseData", Utilitycl.ELEMENTTYPE.INPUT);
responseData = responseData.Replace("&", "&");
responseData = HttpUtility.UrlEncode(responseData);
using (WebClient wc = new WebClient())
{
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    string HtmlResult = wc.UploadString("https://example.com/test.php", "authRespCode=1&responseData = " + responseData);
}
相关问题