WebClient.UploadData修正后要求使用 [英] WebClient.UploadData correct usage for post request
问题描述
我想我会有点疯狂,当我测试这对我的本地网络服务器,它工作正常
,当我走出去活的网站,它返回一个空字符串,而不是我期待中的数据
我不认为熟悉C#,所以我只是想检查我在做正确的事情。
中的数据仅仅是ASCII纯文本
WC =新的WebClient();
wc.Headers.Add(内容类型,应用程序/ x-WWW的形式,进行了urlencoded);
响应= wc.UploadData(this.urlUpdate,Encoding.ASCII.GetBytes(数据=+ HttpUtility.UrlEncode(buf.ToString())));
S = Encoding.ASCII.GetString(响应);
这真的取决于你正在尝试做的.. 。我不知道,比如为什么你在身体URL编码数据。张贴键/值对一个更简单的方法是使用 UploadValues
;
NameValueCollection中输入=新的NameValueCollection();
字符串值= ...
inputs.Add(数据,价值);
webClient.UploadValues(地址输入);
i think i am going a bit crazy, when i test this on my local webserver, it works fine when i go out to the live website, it returns a blank string instead of the data i am expecting
i am not that familiar with C#, so i just wanted to check i am doing things right. the data is just plain ascii text
wc = new WebClient();
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
response = wc.UploadData(this.urlUpdate, Encoding.ASCII.GetBytes("data=" + HttpUtility.UrlEncode(buf.ToString())));
s = Encoding.ASCII.GetString(response);
It really depends what you are trying to do... I'm not sure, for example, why you are url-encoding data in the body. An easier way to post key/value pairs is with UploadValues
;
NameValueCollection inputs = new NameValueCollection();
string value = ...
inputs.Add("data", value);
webClient.UploadValues(address, inputs);
这篇关于WebClient.UploadData修正后要求使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!