我试图用HTTP服务器连接并发送一些日期。我的代码看起来像 - >发送POST数据
public MainPage()
{
InitializeComponent();
WebClient client = new WebClient();
Uri uri = new Uri("http://google.pl");
string data = "Time = 12:00am temperature = 50";
client.UploadStringCompleted += new UploadStringCompletedEventHandler (UploadStringCallback2);
client.UploadStringAsync(uri, data);
}
private static void UploadStringCallback2(Object sender, UploadStringCompletedEventArgs e)
{
string reply = (string)e.Result;
Console.WriteLine(reply);
}
我收到异常“远程服务器返回错误:NotFound。”我的调试窗口看起来像
在System.Windows.dll中发生类型'System.Net.WebException'的第一次机会异常 在System.Windows.dll中发生类型'System.Net.WebException'的第一次机会异常 System.dll中发生第一次机会异常'System.Net.WebException'
请帮忙! PS:我已经安装了7.1 SDK Beta,但它应该在7.0模拟器上运行(Target windows phone verison是WP7)。
编辑:
现在的代码看起来像
Uri uri = new Uri("MY SITE");
string data = "text=dupa";
//client.Encoding = System.Text.Encoding.UTF8;
var headers = new WebHeaderCollection();
headers[0] = " User-Agent: CERN-LineMode/2.15 libwww/2.17b3";
client.Headers = headers;
client.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadStringCallback2);
client.UploadStringAsync(uri, data);
它连接到我的PHP脚本
<?php
print_r($_POST);
print_r($_SERVER[HTTP_USER_AGENT]);
?>
,但反应就像
Array
(
)
NativeHost
在此先感谢您的帮助:)
编辑: OK,我理解了它;)一切工作;)
它帮助了一点:/现在我收到我的PHP脚本,但POST和我送空头回应:/(我编辑我的问题)。 –