【问题标题】:Webclient.UploadString() sends an empty stringWebclient.UploadString() 发送一个空字符串
【发布时间】:2012-05-07 12:01:10
【问题描述】:

这里有一些代码:

var client = new WebClient();
client.BaseAddress = "http://localhost/";
client.Headers["Content-type"] = "application/x-www-form-urlencoded";
client.Proxy = null;
// The server gets the data
var responseStr = client.UploadString(url, data); 
...
// The server gets an empty post data
responseStr = client.UploadString(url, data); 

Webclient 应该是一次性的吗?

【问题讨论】:

  • data 变量的内容是什么?
  • 一对密钥:json=foo&checksum=sha1(foo)。我觉得没关系。
  • 其实这很重要,因为如果你没有正确编码,服务器将无法解码。
  • 我用相同的数据和 url 测试了 UploadString 两次。当我每次创建一个新的 WebClient 时,一切正常。

标签: c# post webclient


【解决方案1】:

嗯,也许你不能试试这个:

WebClient client = new WebClient();
client.BaseAddress = "http://localhost/something.php";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多