如何在c#中使用JSON格式的GET方法向php webservice发送数据


how to send data to php webservice using GET method in JSON Format in C#

我是webservice的新手,我正试图将JSON数据从我在VS2010中创建的WP7应用程序发送到。php webservice。我已经使用了UploadStringAsync方法,但是这个方法不能与GET方法一起工作。在使用GET方法时抛出异常。请帮助。

是我的c#代码

WebClient postWithParamsClient = new WebClient();
postWithParamsClient.Headers["Content-type"] = "application/json";
postWithParamsClient.UploadStringCompleted += new UploadStringCompletedEventHandler(postWithParamsClient_UploadStringCompleted);
postWithParamsClient.UploadStringAsync(url, "POST", "{ '"latitude'": " + textBox2.Text.ToString() + ", '"longitude'": " + textBox3.Text.ToString() + " }");

下面是我的webservice

<?php
/*XML FORMAT
<gpstrack>
    <latitude>30°N</latitude>
    <longitude>38°N</longitude>
    <mobtime>mobiletime</mobtime>
</gpstrack>
XML FORMAT*/
$xml = file_get_contents('php://input');
$finalArray = json_decode(json_encode((array) simplexml_load_string($xml)),1);
//$finalArray=array('latitude'=>'12.1','longitude'=>'3.2','mobtime'=>'325695142');
$newfb = new TABLE($db,"gpslog","track_id");
$newfb -> latitude              = $finalArray['latitude'];
$newfb -> longitude             = $finalArray['longitude'];
$newfb -> mobtime               = strtotime($finalArray['mobtime']);
$newfb -> insert(); 
print "success";
exit;
?>

如果要使用GET方法,请使用DownloadStringAsync