这就是我所拥有的
using Windows.Web.Http;
using Windows.Web.Http.Headers;
public async static Task<bool> FormPost(List<KeyValuePair<string, string>> varvaluepair, string hosturl)
{
try
{
Uri cURI;
if (Uri.TryCreate(hosturl, UriKind.Absolute, out cURI) && (cURI.Scheme == "http" || cURI.Scheme == "https"))
{
var client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.ParseAdd("ie");
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
var content = new HttpFormUrlEncodedContent(varvaluepair);
content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded");
var response = await client.PostAsync(cURI, content);
if (response.IsSuccessStatusCode)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
这是我从回复中得到的:
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 2, Content: Windows.Web.Http.HttpStreamContent, Headers:
{
Connection: keep-alive
Server: nginx admin
Date: Sun, 11 May 2014 15:46:32 GMT
}{
Content-Length: 335
Content-Type: text/html; charset=iso-8859-1
}} Windows.Web.Http.HttpResponseMessage
我的主机收到提交值,除了 404 的响应和返回 false 而不是 true 的函数外,一切正常。
这就是我发送的方式:
string tmpAddress = "http://www.somewhere.com";
var tmpData = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Name", "Jibah xxxxxxxxxxxx"),
new KeyValuePair<string, string>("Email", "jibah.kxxxxx@xxxx.com"),
new KeyValuePair<string, string>("Feedback", "Test submission to see the response"),
new KeyValuePair<string, string>("form_tools_form_id", "225")
};
bool tmpResult = await FormPost(tmpData, tmpAddress);
以及来自 Formtool 网站的结果(我无法发布图像) 图像捕获
原谅我的英语。谢谢。